Skip to content

Commit

Permalink
Fix a bug in top-level type inference dependency tracking
Browse files Browse the repository at this point in the history
When there was a top-level type inference dependency from a declared
field to an overridden getter or setter, the dependency was not
recorded in the field.  This caused initializing formals to sometimes
fail to infer the field type, because they did not see that it needed
to be inferred.

Fixes #32866

Change-Id: If75658d087c099787f74af5f5c6db2ee6837febe
Reviewed-on: https://dart-review.googlesource.com/62800
Commit-Queue: Kevin Millikin <kmillikin@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
  • Loading branch information
Kevin Millikin authored and commit-bot@chromium.org committed Jun 28, 2018
1 parent 29924c4 commit b0cbc4e
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,9 @@ class InterfaceResolver {
procedure._field.initializer != null) {
node = new FieldInitializerInferenceNode(
_typeInferenceEngine, procedure._field, library);
}

if (node != null && procedure is SyntheticAccessor) {
ShadowField.setInferenceNode(procedure._field, node);
}
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/front_end/testcases/bug32866.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2018, 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.

// Regression test that top-level inference correctly handles dependencies from
// top-level field -> initializing formal -> field that overrides a getter.

abstract class B {
String get f;
}

class A implements B {
final f;
A(this.f);
}

var a = new A("foo");
main() => print(a);
19 changes: 19 additions & 0 deletions pkg/front_end/testcases/bug32866.dart.direct.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
library;
import self as self;
import "dart:core" as core;

abstract class B extends core::Object {
synthetic constructor •() → void
: super core::Object::•()
;
abstract get f() → core::String;
}
class A extends core::Object implements self::B {
final field dynamic f;
constructor •(dynamic f) → void
: self::A::f = f, super core::Object::•()
;
}
static field dynamic a = new self::A::•("foo");
static method main() → dynamic
return core::print(self::a);
19 changes: 19 additions & 0 deletions pkg/front_end/testcases/bug32866.dart.direct.transformed.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
library;
import self as self;
import "dart:core" as core;

abstract class B extends core::Object {
synthetic constructor •() → void
: super core::Object::•()
;
abstract get f() → core::String;
}
class A extends core::Object implements self::B {
final field dynamic f;
constructor •(dynamic f) → void
: self::A::f = f, super core::Object::•()
;
}
static field dynamic a = new self::A::•("foo");
static method main() → dynamic
return core::print(self::a);
17 changes: 17 additions & 0 deletions pkg/front_end/testcases/bug32866.dart.outline.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
library;
import self as self;
import "dart:core" as core;

abstract class B extends core::Object {
synthetic constructor •() → void
;
abstract get f() → core::String;
}
class A extends core::Object implements self::B {
final field dynamic f;
constructor •(dynamic f) → void
;
}
static field dynamic a;
static method main() → dynamic
;
19 changes: 19 additions & 0 deletions pkg/front_end/testcases/bug32866.dart.strong.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
library;
import self as self;
import "dart:core" as core;

abstract class B extends core::Object {
synthetic constructor •() → void
: super core::Object::•()
;
abstract get f() → core::String;
}
class A extends core::Object implements self::B {
final field core::String f;
constructor •(core::String f) → void
: self::A::f = f, super core::Object::•()
;
}
static field self::A a = new self::A::•("foo");
static method main() → dynamic
return core::print(self::a);
19 changes: 19 additions & 0 deletions pkg/front_end/testcases/bug32866.dart.strong.transformed.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
library;
import self as self;
import "dart:core" as core;

abstract class B extends core::Object {
synthetic constructor •() → void
: super core::Object::•()
;
abstract get f() → core::String;
}
class A extends core::Object implements self::B {
final field core::String f;
constructor •(core::String f) → void
: self::A::f = f, super core::Object::•()
;
}
static field self::A a = new self::A::•("foo");
static method main() → dynamic
return core::print(self::a);

0 comments on commit b0cbc4e

Please sign in to comment.