Skip to content

Commit

Permalink
#1087. More function tear-offs tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Jun 10, 2021
1 parent 4d770fd commit dfab47f
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2021, 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.

/// @assertion We do not allow dynamic explicit instantiation. If an expression
/// e has type dynamic (or Never), then e.foo<int> is a compile-time error for
/// any name foo. (It'd be valid for a member of Object that was a generic
/// function, but none of the Object members are generic functions). It's not
/// possible to do implicit instantiation without knowing the member signature.
///
/// @description Checks that dynamic explicit instantiation is a compile-time
/// error
/// @author sgrekhov@unipro.ru
// SharedOptions=--enable-experiment=constructor-tearoffs

main() {
dynamic d = new Object();
d.foo<int>;
// ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2021, 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.

/// @assertion We do not allow dynamic explicit instantiation. If an expression
/// e has type dynamic (or Never), then e.foo<int> is a compile-time error for
/// any name foo. (It'd be valid for a member of Object that was a generic
/// function, but none of the Object members are generic functions). It's not
/// possible to do implicit instantiation without knowing the member signature.
///
/// @description Checks that dynamic explicit instantiation is a compile-time
/// error
/// @author sgrekhov@unipro.ru
// SharedOptions=--enable-experiment=constructor-tearoffs

dynamic f(dynamic x) => x;

class C {
T instanceMethod<T>(T t) => t;
}

main() {
C c = new C();
var v1 = f(c).instanceMethod<int>;
// ^^^^^^^^^^^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2021, 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.

/// @assertion These grammar changes allows type parameters without following
/// parenthesized arguments in places where we previously did not allow them.
/// For example, this means that <typeArguments> becomes a selector by itself,
/// not just followed by arguments.
//
// It applies to instance methods as well as local, static and top-level
// function declarations. For instance methods, it applies to references of the
// form
//
// instanceMethod<int> (with implicit this),
// object.instanceMethod<int> (including this) and super.instanceMethod<int>.
///
/// @description Checks tear-off of generic static method
/// @author sgrekhov@unipro.ru
// SharedOptions=--enable-experiment=constructor-tearoffs

import "../../Utils/expect.dart";

class C {
static T staticMethod<T>(T t) => t;
}

main() {
var x = C.staticMethod<int>;
Expect.equals(42, x(42));
dynamic d1 = -42;
Expect.isTrue(x(d1) is int);
Expect.isFalse(x(d1) is double); // to check that returned type is not dynamic
dynamic d2 = 3.14;
Expect.throws(() {x(d2);});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2021, 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.

/// @assertion These grammar changes allows type parameters without following
/// parenthesized arguments in places where we previously did not allow them.
/// For example, this means that <typeArguments> becomes a selector by itself,
/// not just followed by arguments.
//
// It applies to instance methods as well as local, static and top-level
// function declarations. For instance methods, it applies to references of the
// form
//
// instanceMethod<int> (with implicit this),
// object.instanceMethod<int> (including this) and super.instanceMethod<int>.
///
/// @description Checks tear-off of generic instance method
/// @author sgrekhov@unipro.ru
// SharedOptions=--enable-experiment=constructor-tearoffs

class C {
static T staticMethod<T>(T t) => t;
}

main() {
var x = C.staticMethod<int>;
x(3.14);
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
x<double>(42);
// ^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2021, 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.

/// @assertion The static type of the instantiated type literal is Type
///
/// @description Check that the static type of the instantiated type literal is
/// Type
/// @author sgrekhov@unipro.ru
// SharedOptions=--enable-experiment=constructor-tearoffs

import "../../Utils/expect.dart";

main() {
var intList = List<int>;
Expect.isTrue(intList is Type);
Expect.isFalse(intList is List<double>); // to check that intList is not dynamic
}

0 comments on commit dfab47f

Please sign in to comment.