-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vm] Prevent late fields from being unboxed
When unboxed doubles are assigned to late fields, it conflicts with the late field logic and causes a crash. Bug: #38841 Bug: #39658 Change-Id: I641f597006114f02473a20f8c2526eeaf4fe813f Fixes: #39658 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127442 Commit-Queue: Liam Appelbe <liama@google.com> Reviewed-by: Alexander Markov <alexmarkov@google.com>
- Loading branch information
1 parent
7ac3f3e
commit e20ff1e
Showing
8 changed files
with
112 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// SharedOptions=--enable-experiment=non-nullable | ||
import 'package:expect/expect.dart'; | ||
|
||
int initCalls = 0; | ||
double init() { | ||
++initCalls; | ||
return 1.23; | ||
} | ||
|
||
class A { | ||
late double? fieldWithInit = init(); | ||
late double fieldWithTrivialInit = 1.23; | ||
late double? fieldWithNullInit = null; | ||
late double fieldWithNoInit; | ||
} | ||
|
||
main() { | ||
// Late, non-final, with init. | ||
var a = A(); | ||
Expect.equals(0, initCalls); | ||
Expect.equals(1.23, a.fieldWithInit); | ||
Expect.equals(1.23, a.fieldWithTrivialInit); | ||
Expect.equals(null, a.fieldWithNullInit); | ||
Expect.throws( | ||
() => a.fieldWithNoInit, (error) => error is LateInitializationError); | ||
Expect.equals(1, initCalls); | ||
Expect.equals(1.23, a.fieldWithInit); | ||
Expect.equals(1.23, a.fieldWithTrivialInit); | ||
Expect.equals(null, a.fieldWithNullInit); | ||
Expect.throws( | ||
() => a.fieldWithNoInit, (error) => error is LateInitializationError); | ||
Expect.equals(1, initCalls); | ||
a.fieldWithInit = 4.56; | ||
a.fieldWithTrivialInit = 4.56; | ||
a.fieldWithNullInit = 4.56; | ||
a.fieldWithNoInit = 4.56; | ||
Expect.equals(1, initCalls); | ||
Expect.equals(4.56, a.fieldWithInit); | ||
Expect.equals(4.56, a.fieldWithTrivialInit); | ||
Expect.equals(4.56, a.fieldWithNullInit); | ||
Expect.equals(4.56, a.fieldWithNoInit); | ||
Expect.equals(1, initCalls); | ||
initCalls = 0; | ||
|
||
// Late, non-final, with init that's pre-empted by setter. | ||
var b = A(); | ||
Expect.equals(0, initCalls); | ||
b.fieldWithInit = 4.56; | ||
Expect.equals(0, initCalls); | ||
Expect.equals(4.56, b.fieldWithInit); | ||
Expect.equals(0, initCalls); | ||
|
||
// Late, non-final, with init that's pre-empted by null setter. | ||
var c = A(); | ||
Expect.equals(0, initCalls); | ||
c.fieldWithInit = null; | ||
Expect.equals(0, initCalls); | ||
Expect.equals(null, c.fieldWithInit); | ||
Expect.equals(0, initCalls); | ||
} |