Fix typechecks for constant assignments of function to typedefs.
R=karlklose@google.com Review URL: https://codereview.chromium.org//132313012 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32432 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
@@ -75,9 +75,8 @@ class FunctionConstant extends Constant {
|
||||
return new DartString.literal(element.name);
|
||||
}
|
||||
|
||||
DartType computeType(Compiler compiler) {
|
||||
return compiler.functionClass.computeType(compiler);
|
||||
}
|
||||
// TODO(johnniwinther): remove computeType.
|
||||
DartType computeType(Compiler compiler) => element.computeType(compiler);
|
||||
|
||||
ti.TypeMask computeMask(Compiler compiler) {
|
||||
return compiler.typesTask.functionType;
|
||||
|
||||
@@ -666,7 +666,9 @@ class JavaScriptBackend extends Backend {
|
||||
|
||||
void registerInstantiatedConstantType(DartType type, TreeElements elements) {
|
||||
Enqueuer enqueuer = compiler.enqueuer.codegen;
|
||||
enqueuer.registerInstantiatedType(type, elements);
|
||||
DartType instantiatedType =
|
||||
type.kind == TypeKind.FUNCTION ? compiler.functionClass.rawType : type;
|
||||
enqueuer.registerInstantiatedType(instantiatedType, elements);
|
||||
if (type is InterfaceType && !type.treatAsRaw &&
|
||||
classNeedsRti(type.element)) {
|
||||
enqueuer.registerStaticUse(getSetRuntimeTypeInfo());
|
||||
|
||||
@@ -46,6 +46,7 @@ compile_time_constant_checked3_test/03: Fail, OK
|
||||
compile_time_constant_checked3_test/04: Fail, OK
|
||||
compile_time_constant_checked3_test/05: Fail, OK
|
||||
compile_time_constant_checked3_test/06: Fail, OK
|
||||
type_check_const_function_typedef2_test/00: MissingCompileTimeError, OK
|
||||
malformed2_test/01: Fail, OK
|
||||
|
||||
[ $runtime == vm || (($runtime == drt || $runtime == dartium) && $compiler == none) ]
|
||||
|
||||
@@ -26,6 +26,8 @@ assignable_expression_test/42: Fail # Issue 15471
|
||||
|
||||
unicode_bom_test: Fail # Issue 16314
|
||||
|
||||
type_check_const_function_typedef2_test/00: MissingCompileTimeError, Ok # Compile-time error in checked mode, because of constants.
|
||||
|
||||
# Please add new failing tests before this line.
|
||||
# Section below is for invalid tests.
|
||||
#
|
||||
|
||||
@@ -26,6 +26,8 @@ assignable_expression_test/42: Fail # Issue 15471
|
||||
|
||||
unicode_bom_test: Fail # Issue 16314
|
||||
|
||||
type_check_const_function_typedef2_test/00: MissingCompileTimeError, Ok # Compile-time error in checked mode, because of constants.
|
||||
|
||||
# Please add new failing tests before this line.
|
||||
# Section below is for invalid tests.
|
||||
#
|
||||
|
||||
@@ -75,6 +75,7 @@ compile_time_constant_checked3_test/03: MissingCompileTimeError, OK
|
||||
compile_time_constant_checked3_test/04: MissingCompileTimeError, OK
|
||||
compile_time_constant_checked3_test/05: MissingCompileTimeError, OK
|
||||
compile_time_constant_checked3_test/06: MissingCompileTimeError, OK
|
||||
type_check_const_function_typedef2_test/00: MissingCompileTimeError, OK
|
||||
malformed2_test/01: MissingCompileTimeError, OK
|
||||
generic_test: RuntimeError, OK
|
||||
named_parameters_type_test/01: MissingRuntimeError, OK
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2014, 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.
|
||||
|
||||
// Tests that typechecks on const objects with typedefs work.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
typedef String Int2String(int x);
|
||||
|
||||
class A {
|
||||
final Int2String f;
|
||||
const A(this.f);
|
||||
}
|
||||
|
||||
int /// 00: compile-time error
|
||||
foo(
|
||||
String /// 00: continued
|
||||
x) => 499;
|
||||
|
||||
const a = const A(foo);
|
||||
|
||||
main() {
|
||||
Expect.equals(499, a.f(499));
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2014, 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.
|
||||
|
||||
// Tests that typechecks on const objects with typedefs work.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
typedef String Int2String(int x);
|
||||
|
||||
class A {
|
||||
final Int2String f;
|
||||
const A(this.f);
|
||||
}
|
||||
|
||||
String foo(int x) => "str";
|
||||
|
||||
const a = const A(foo);
|
||||
|
||||
main() {
|
||||
Expect.equals("str", a.f(499));
|
||||
}
|
||||
Reference in New Issue
Block a user