mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:22:12 +00:00
Implement type inference for super initializers.
R=scheglov@google.com Review-Url: https://codereview.chromium.org/2992263002 .
This commit is contained in:
parent
4929f282b3
commit
1b03375d62
|
@ -3204,7 +3204,7 @@ class BodyBuilder extends ScopeListener<JumpTarget> implements BuilderHelper {
|
|||
charOffset);
|
||||
}
|
||||
needsImplicitSuperInitializer = false;
|
||||
return new SuperInitializer(constructor, arguments)
|
||||
return new KernelSuperInitializer(constructor, arguments)
|
||||
..fileOffset = charOffset
|
||||
..isSynthetic = isSynthetic;
|
||||
}
|
||||
|
|
|
@ -1806,6 +1806,22 @@ class KernelStringLiteral extends StringLiteral implements KernelExpression {
|
|||
}
|
||||
}
|
||||
|
||||
/// Concrete shadow object representing a super initializer in kernel form.
|
||||
class KernelSuperInitializer extends SuperInitializer
|
||||
implements KernelInitializer {
|
||||
KernelSuperInitializer(Constructor target, Arguments arguments)
|
||||
: super(target, arguments);
|
||||
|
||||
@override
|
||||
void _inferInitializer(KernelTypeInferrer inferrer) {
|
||||
inferrer.listener.superInitializerEnter(this);
|
||||
inferrer.inferInvocation(null, false, fileOffset,
|
||||
target.function.functionType, target.enclosingClass.thisType, arguments,
|
||||
skipTypeArgumentInference: true);
|
||||
inferrer.listener.superInitializerExit(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// Shadow object for [SuperMethodInvocation].
|
||||
class KernelSuperMethodInvocation extends SuperMethodInvocation
|
||||
implements KernelExpression {
|
||||
|
|
|
@ -358,6 +358,12 @@ class TypeInferenceListener
|
|||
void stringLiteralExit(StringLiteral expression, DartType inferredType) =>
|
||||
genericExpressionExit("StringLiteral", expression, inferredType);
|
||||
|
||||
void superInitializerEnter(SuperInitializer initializer) =>
|
||||
genericInitializerEnter("superInitializer", initializer);
|
||||
|
||||
void superInitializerExit(SuperInitializer initializer) =>
|
||||
genericInitializerExit("superInitializer", initializer);
|
||||
|
||||
void switchStatementEnter(SwitchStatement statement) =>
|
||||
genericStatementEnter('switchStatement', statement);
|
||||
|
||||
|
|
|
@ -295,6 +295,7 @@ inference/refine_binary_expression_type_type_parameter_t_t: Crash
|
|||
inference/static_method_tear_off: Crash
|
||||
inference/string_literal: Crash
|
||||
inference/subexpressions_of_explicitly_typed_fields: Crash
|
||||
inference/super_initializer: Crash
|
||||
inference/super_method_invocation: Crash
|
||||
inference/super_property_get: Crash
|
||||
inference/super_property_get_invoke_function_typed: Crash
|
||||
|
|
18
pkg/front_end/testcases/inference/super_initializer.dart
Normal file
18
pkg/front_end/testcases/inference/super_initializer.dart
Normal file
|
@ -0,0 +1,18 @@
|
|||
// 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.
|
||||
|
||||
/*@testedFeatures=inference*/
|
||||
library test;
|
||||
|
||||
T f<T>() => null;
|
||||
|
||||
class C extends B {
|
||||
C() : super(/*@typeArgs=int*/ f());
|
||||
}
|
||||
|
||||
class B {
|
||||
B(int x);
|
||||
}
|
||||
|
||||
main() {}
|
|
@ -0,0 +1,17 @@
|
|||
library test;
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
class C extends self::B {
|
||||
constructor •() → void
|
||||
: super self::B::•(self::f<dynamic>())
|
||||
;
|
||||
}
|
||||
class B extends core::Object {
|
||||
constructor •(core::int x) → void
|
||||
: super core::Object::•()
|
||||
;
|
||||
}
|
||||
static method f<T extends core::Object>() → self::f::T
|
||||
return null;
|
||||
static method main() → dynamic {}
|
|
@ -0,0 +1,16 @@
|
|||
library test;
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
class C extends self::B {
|
||||
constructor •() → void
|
||||
;
|
||||
}
|
||||
class B extends core::Object {
|
||||
constructor •(core::int x) → void
|
||||
;
|
||||
}
|
||||
static method f<T extends core::Object>() → self::f::T
|
||||
;
|
||||
static method main() → dynamic
|
||||
;
|
|
@ -0,0 +1,17 @@
|
|||
library test;
|
||||
import self as self;
|
||||
import "dart:core" as core;
|
||||
|
||||
class C extends self::B {
|
||||
constructor •() → void
|
||||
: super self::B::•(self::f<core::int>())
|
||||
;
|
||||
}
|
||||
class B extends core::Object {
|
||||
constructor •(core::int x) → void
|
||||
: super core::Object::•()
|
||||
;
|
||||
}
|
||||
static method f<T extends core::Object>() → self::f::T
|
||||
return null;
|
||||
static method main() → dynamic {}
|
Loading…
Reference in a new issue