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:
Robert Nystrom 2020-02-04 15:07:11 +00:00 committed by commit-bot@chromium.org
parent f0d16c3c31
commit c5cba24124
13 changed files with 414 additions and 0 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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
}

View file

@ -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);
}

View 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));
}

View 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);
}

View file

@ -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.
}

View file

@ -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();
}

View file

@ -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)) {}

View file

@ -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)) {}

View file

@ -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)) {}