mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:58:29 +00:00
keep null check on virtual field
We weren't correctly blocking the opt if the field was marked virtual R=leafp@google.com Review-Url: https://codereview.chromium.org/2693593002 .
This commit is contained in:
parent
1f02e4ebf0
commit
986a1c2775
|
@ -81,7 +81,8 @@ abstract class NullableTypeInference {
|
|||
|
||||
if (element is PropertyAccessorElement && element.isGetter) {
|
||||
PropertyInducingElement variable = element.variable;
|
||||
return variable.computeConstantValue()?.isNull ?? true;
|
||||
var isVirtual = variable is FieldElement && variable.isVirtual;
|
||||
return isVirtual || (variable.computeConstantValue()?.isNull ?? true);
|
||||
}
|
||||
|
||||
// Other types of identifiers are nullable (parameters, fields).
|
||||
|
|
|
@ -52,6 +52,7 @@ require.config({
|
|||
expect: 'gen/codegen_output/pkg/expect',
|
||||
js: 'gen/codegen_output/pkg/js',
|
||||
matcher: 'gen/codegen_output/pkg/matcher',
|
||||
meta: 'gen/codegen_output/pkg/meta',
|
||||
minitest: 'gen/codegen_output/pkg/minitest',
|
||||
path: 'gen/codegen_output/pkg/path',
|
||||
stack_trace: 'gen/codegen_output/pkg/stack_trace',
|
||||
|
|
|
@ -22,9 +22,9 @@ void main(List<String> arguments) {
|
|||
compileModule('async_helper');
|
||||
compileModule('expect', libs: ['minitest']);
|
||||
compileModule('js', libs: ['js_util']);
|
||||
compileModule('meta');
|
||||
if (!test) {
|
||||
compileModule('lookup_map');
|
||||
compileModule('meta');
|
||||
compileModule('microlytics', libs: ['html_channels']);
|
||||
compileModule('typed_mock');
|
||||
}
|
||||
|
|
33
tests/language_strong/field_override_optimization_test.dart
Normal file
33
tests/language_strong/field_override_optimization_test.dart
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright (c) 2017, 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.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
import "package:meta/meta.dart";
|
||||
|
||||
class A {
|
||||
@virtual final bool flag = true;
|
||||
@virtual final int x = 42;
|
||||
}
|
||||
|
||||
class B extends A {
|
||||
bool flag;
|
||||
int x;
|
||||
}
|
||||
|
||||
void main() {
|
||||
A a = new B();
|
||||
var exception;
|
||||
try {
|
||||
if (a.flag) {
|
||||
Expect.fail('This should be unreachable');
|
||||
} else {
|
||||
Expect.fail('This should also be unreachable');
|
||||
}
|
||||
} on AssertionError catch(e) {
|
||||
exception = e;
|
||||
}
|
||||
Expect.isTrue(exception is AssertionError);
|
||||
Expect.throws(() => a.x + 8);
|
||||
}
|
||||
|
Loading…
Reference in a new issue