mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 09:43:57 +00:00
Migrate language_2/argument to NNBD.
Change-Id: Ic1963eb1962bc1341a68783e9c44f3e04bfbc43a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134223 Auto-Submit: Bob Nystrom <rnystrom@google.com> Commit-Queue: Erik Ernst <eernst@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
This commit is contained in:
parent
f0d16c3c31
commit
c5cba24124
|
@ -0,0 +1,40 @@
|
|||
// TODO(multitest): This was automatically migrated from a multitest and may
|
||||
// contain strange or dead code.
|
||||
|
||||
// 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";
|
||||
|
||||
void f(num callback(num x)) {}
|
||||
|
||||
Object intToObject(int x) => 0;
|
||||
Object numToObject(num x) => 0;
|
||||
Object objectToObject(Object x) => 0;
|
||||
int intToInt(int x) => 0;
|
||||
int numToInt(num x) => 0;
|
||||
int objectToInt(Object x) => 0;
|
||||
num intToNum(int x) => 0;
|
||||
num numToNum(num x) => 0;
|
||||
num objectToNum(Object x) => 0;
|
||||
|
||||
main() {
|
||||
// Unrelated types (not assignable)
|
||||
|
||||
|
||||
|
||||
// Assignable but fails at runtime.
|
||||
var intToObject2 = intToObject;
|
||||
|
||||
var intToNum2 = intToNum;
|
||||
|
||||
var numToObject2 = numToObject;
|
||||
|
||||
|
||||
// Ok
|
||||
f(numToNum);
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
// TODO(multitest): This was automatically migrated from a multitest and may
|
||||
// contain strange or dead code.
|
||||
|
||||
// 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";
|
||||
|
||||
void f(num callback(num x)) {}
|
||||
|
||||
Object intToObject(int x) => 0;
|
||||
Object numToObject(num x) => 0;
|
||||
Object objectToObject(Object x) => 0;
|
||||
int intToInt(int x) => 0;
|
||||
int numToInt(num x) => 0;
|
||||
int objectToInt(Object x) => 0;
|
||||
num intToNum(int x) => 0;
|
||||
num numToNum(num x) => 0;
|
||||
num objectToNum(Object x) => 0;
|
||||
|
||||
main() {
|
||||
// Unrelated types (not assignable)
|
||||
|
||||
|
||||
|
||||
// Assignable but fails at runtime.
|
||||
var intToObject2 = intToObject;
|
||||
|
||||
var intToNum2 = intToNum;
|
||||
|
||||
var numToObject2 = numToObject;
|
||||
|
||||
|
||||
// Ok
|
||||
|
||||
f(numToInt);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
// TODO(multitest): This was automatically migrated from a multitest and may
|
||||
// contain strange or dead code.
|
||||
|
||||
// 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";
|
||||
|
||||
void f(num callback(num x)) {}
|
||||
|
||||
Object intToObject(int x) => 0;
|
||||
Object numToObject(num x) => 0;
|
||||
Object objectToObject(Object x) => 0;
|
||||
int intToInt(int x) => 0;
|
||||
int numToInt(num x) => 0;
|
||||
int objectToInt(Object x) => 0;
|
||||
num intToNum(int x) => 0;
|
||||
num numToNum(num x) => 0;
|
||||
num objectToNum(Object x) => 0;
|
||||
|
||||
main() {
|
||||
// Unrelated types (not assignable)
|
||||
|
||||
|
||||
|
||||
// Assignable but fails at runtime.
|
||||
var intToObject2 = intToObject;
|
||||
|
||||
var intToNum2 = intToNum;
|
||||
|
||||
var numToObject2 = numToObject;
|
||||
|
||||
|
||||
// Ok
|
||||
|
||||
|
||||
f(objectToNum);
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
// TODO(multitest): This was automatically migrated from a multitest and may
|
||||
// contain strange or dead code.
|
||||
|
||||
// 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";
|
||||
|
||||
void f(num callback(num x)) {}
|
||||
|
||||
Object intToObject(int x) => 0;
|
||||
Object numToObject(num x) => 0;
|
||||
Object objectToObject(Object x) => 0;
|
||||
int intToInt(int x) => 0;
|
||||
int numToInt(num x) => 0;
|
||||
int objectToInt(Object x) => 0;
|
||||
num intToNum(int x) => 0;
|
||||
num numToNum(num x) => 0;
|
||||
num objectToNum(Object x) => 0;
|
||||
|
||||
main() {
|
||||
// Unrelated types (not assignable)
|
||||
|
||||
|
||||
|
||||
// Assignable but fails at runtime.
|
||||
var intToObject2 = intToObject;
|
||||
|
||||
var intToNum2 = intToNum;
|
||||
|
||||
var numToObject2 = numToObject;
|
||||
|
||||
|
||||
// Ok
|
||||
|
||||
|
||||
|
||||
f(objectToInt);
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
// TODO(multitest): This was automatically migrated from a multitest and may
|
||||
// contain strange or dead code.
|
||||
|
||||
// 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";
|
||||
|
||||
void f(num callback(num x)) {}
|
||||
|
||||
Object intToObject(int x) => 0;
|
||||
Object numToObject(num x) => 0;
|
||||
Object objectToObject(Object x) => 0;
|
||||
int intToInt(int x) => 0;
|
||||
int numToInt(num x) => 0;
|
||||
int objectToInt(Object x) => 0;
|
||||
num intToNum(int x) => 0;
|
||||
num numToNum(num x) => 0;
|
||||
num objectToNum(Object x) => 0;
|
||||
|
||||
main() {
|
||||
// Unrelated types (not assignable)
|
||||
|
||||
|
||||
|
||||
// Assignable but fails at runtime.
|
||||
var intToObject2 = intToObject;
|
||||
|
||||
var intToNum2 = intToNum;
|
||||
|
||||
var numToObject2 = numToObject;
|
||||
|
||||
|
||||
// Ok
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
// 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";
|
||||
|
||||
void f(num callback(num x)) {}
|
||||
|
||||
Object intToObject(int x) => 0;
|
||||
Object numToObject(num x) => 0;
|
||||
Object objectToObject(Object x) => 0;
|
||||
int intToInt(int x) => 0;
|
||||
int numToInt(num x) => 0;
|
||||
int objectToInt(Object x) => 0;
|
||||
num intToNum(int x) => 0;
|
||||
num numToNum(num x) => 0;
|
||||
num objectToNum(Object x) => 0;
|
||||
|
||||
main() {
|
||||
// Unrelated types (not assignable).
|
||||
f(intToInt);
|
||||
//^^^^^^^^
|
||||
// [analyzer] STATIC_WARNING.ARGUMENT_TYPE_NOT_ASSIGNABLE
|
||||
// [cfe] The argument type 'int Function(int)' can't be assigned to the parameter type 'num Function(num)'.
|
||||
f(objectToObject);
|
||||
//^^^^^^^^^^^^^^
|
||||
// [analyzer] STATIC_WARNING.ARGUMENT_TYPE_NOT_ASSIGNABLE
|
||||
// [cfe] The argument type 'Object Function(Object)' can't be assigned to the parameter type 'num Function(num)'.
|
||||
|
||||
// Downcasts.
|
||||
f(intToObject);
|
||||
//^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.INVALID_CAST_FUNCTION
|
||||
// [cfe] The top level function has type 'Object Function(int)' that isn't of expected type 'num Function(num)'.
|
||||
f(intToNum);
|
||||
//^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.INVALID_CAST_FUNCTION
|
||||
// [cfe] The top level function has type 'num Function(int)' that isn't of expected type 'num Function(num)'.
|
||||
f(numToObject);
|
||||
//^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.INVALID_CAST_FUNCTION
|
||||
// [cfe] The top level function has type 'Object Function(num)' that isn't of expected type 'num Function(num)'.
|
||||
|
||||
// Ok.
|
||||
f(numToNum);
|
||||
f(numToInt);
|
||||
f(objectToNum);
|
||||
f(objectToInt);
|
||||
}
|
16
tests/language/argument/named_argument_test.dart
Normal file
16
tests/language/argument/named_argument_test.dart
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright (c) 2012, 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";
|
||||
|
||||
main() {
|
||||
var c1 = ({b, a}) => 'a: $a b: $b';
|
||||
var c2 = ({a, b}) => 'a: $a b: $b';
|
||||
|
||||
Expect.equals('a: 2 b: 1', c1(b: 1, a: 2));
|
||||
Expect.equals('a: 1 b: 2', c1(a: 1, b: 2));
|
||||
|
||||
Expect.equals('a: 2 b: 1', c2(b: 1, a: 2));
|
||||
Expect.equals('a: 1 b: 2', c2(a: 1, b: 2));
|
||||
}
|
20
tests/language/argument/named_in_const_creation_test.dart
Normal file
20
tests/language/argument/named_in_const_creation_test.dart
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright (c) 2012, 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";
|
||||
|
||||
class A {
|
||||
final x;
|
||||
final y;
|
||||
const A(a, {b})
|
||||
: x = a,
|
||||
y = b;
|
||||
static const test = const A(1, b: 2);
|
||||
}
|
||||
|
||||
main() {
|
||||
A a = A.test;
|
||||
Expect.equals(1, a.x);
|
||||
Expect.equals(2, a.y);
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
// Copyright (c) 2012, 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.
|
||||
|
||||
foo(a, [b]) {}
|
||||
|
||||
bar(a, {b}) {}
|
||||
|
||||
class A {
|
||||
A();
|
||||
A.test(a, [b]);
|
||||
}
|
||||
|
||||
class B {
|
||||
B()
|
||||
: super.test(b: 1)
|
||||
//^^^^^^^^^^^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER
|
||||
// [cfe] Superclass has no constructor named 'Object.test'.
|
||||
;
|
||||
}
|
||||
|
||||
class C extends A {
|
||||
C()
|
||||
: super.test(b: 1)
|
||||
// ^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS
|
||||
// [cfe] Too few positional arguments: 1 required, 0 given.
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER
|
||||
;
|
||||
}
|
||||
|
||||
class D {
|
||||
D();
|
||||
D.test(a, {b});
|
||||
}
|
||||
|
||||
class E extends D {
|
||||
E()
|
||||
: super.test(b: 1)
|
||||
// ^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS
|
||||
// [cfe] Too few positional arguments: 1 required, 0 given.
|
||||
;
|
||||
}
|
||||
|
||||
main() {
|
||||
new A.test(b: 1);
|
||||
// ^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS
|
||||
// [cfe] Too few positional arguments: 1 required, 0 given.
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER
|
||||
new B();
|
||||
new C();
|
||||
new D.test(b: 1);
|
||||
// ^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS
|
||||
// [cfe] Too few positional arguments: 1 required, 0 given.
|
||||
new E();
|
||||
foo(b: 1);
|
||||
// ^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS
|
||||
// [cfe] Too few positional arguments: 1 required, 0 given.
|
||||
// ^
|
||||
// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_NAMED_PARAMETER
|
||||
bar(b: 1);
|
||||
// ^^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.NOT_ENOUGH_POSITIONAL_ARGUMENTS
|
||||
// [cfe] Too few positional arguments: 1 required, 0 given.
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
// TODO(multitest): This was automatically migrated from a multitest and may
|
||||
// contain strange or dead code.
|
||||
|
||||
// Copyright (c) 2012, 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.
|
||||
|
||||
foo(a, [b]) {}
|
||||
|
||||
bar(a, {b}) {}
|
||||
|
||||
class A {
|
||||
A();
|
||||
A.test(a, [b]);
|
||||
}
|
||||
|
||||
class B {
|
||||
B()
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
class C extends A {
|
||||
C()
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
class D {
|
||||
D();
|
||||
D.test(a, {b});
|
||||
}
|
||||
|
||||
class E extends D {
|
||||
E()
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
main() {
|
||||
|
||||
new B();
|
||||
new C();
|
||||
|
||||
new E();
|
||||
|
||||
|
||||
}
|
|
@ -5,6 +5,9 @@
|
|||
// 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.
|
||||
|
||||
// [NNBD non-migrated] Note: This test is specific to legacy mode and
|
||||
// deliberately does not have a counter-part in language/.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void f(num callback(num x)) {}
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
// 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.
|
||||
|
||||
// [NNBD non-migrated] Note: This test is specific to legacy mode and
|
||||
// deliberately does not have a counter-part in language/.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void f(num callback(num x)) {}
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
// 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.
|
||||
|
||||
// [NNBD non-migrated] Note: This test is specific to legacy mode and
|
||||
// deliberately does not have a counter-part in language/.
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
void f(num callback(num x)) {}
|
||||
|
|
Loading…
Reference in a new issue