Migrate language_2/getter to NNBD.

Change-Id: Ibe4be604f5002c125aba64c051793b750f31638a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/147819
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
This commit is contained in:
Robert Nystrom 2020-05-14 19:16:39 +00:00 committed by commit-bot@chromium.org
parent 9c9b17d2f7
commit 415cab79d3
28 changed files with 1284 additions and 0 deletions

View file

@ -0,0 +1,89 @@
// Copyright (c) 2011, 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.
//
// Test that a getter is evaluated after the arguments, when a getter is
// for invoking a method. See chapter 'Method Invocation' in specification.
import "package:expect/expect.dart";
var counter = 0;
class Test1 {
get a {
Expect.equals(1, counter);
counter++;
return (c) {};
}
b() {
Expect.equals(0, counter);
counter++;
return 1;
}
}
class Test2 {
static get a {
Expect.equals(0, counter);
counter++;
return (c) {};
}
static b() {
Expect.equals(1, counter);
counter++;
return 1;
}
}
get a {
Expect.equals(0, counter);
counter++;
return (c) {};
}
b() {
Expect.equals(1, counter);
counter++;
return 1;
}
main() {
var failures = [];
try {
// Check instance getters.
counter = 0;
var o = new Test1();
o.a(o.b());
Expect.equals(2, counter);
} catch (exc, stack) {
failures.add(exc);
failures.add(stack);
}
try {
// Check static getters.
counter = 0;
Test2.a(Test2.b());
Expect.equals(2, counter);
} catch (exc, stack) {
failures.add(exc);
failures.add(stack);
}
try {
// Check top-level getters.
counter = 0;
a(b());
Expect.equals(2, counter);
} catch (exc, stack) {
failures.add(exc);
failures.add(stack);
}
// If any of the tests failed print out the details and fail the test.
if (failures.length != 0) {
for (var msg in failures) {
print(msg.toString());
}
throw "${failures.length ~/ 2} tests failed.";
}
}

View file

@ -0,0 +1,15 @@
// Copyright (c) 2019, 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.
/// Test that a getter takes no parameters.
get m(extraParam) {
// ^
// [analyzer] SYNTACTIC_ERROR.GETTER_WITH_PARAMETERS
// [cfe] A getter can't have formal parameters.
return null;
}
main() {
m;
}

View file

@ -0,0 +1,38 @@
// 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.
// Verifies behavior with a static getter, but no field and no setter.
import "package:expect/expect.dart";
class Example {
static int _var = 1;
static int get nextVar => _var++;
Example() {
}
static test() {
}
}
class Example1 {
Example1(int i) {}
}
class Example2 extends Example1 {
static int _var = 1;
static int get nextVar => _var++;
Example2() : super(nextVar) {} // No 'this' in scope.
}
void main() {
Example x = new Example();
Example.test();
Example2 x2 = new Example2();
}

View file

@ -0,0 +1,54 @@
// 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.
// Verifies behavior with a static getter, but no field and no setter.
import "package:expect/expect.dart";
class Example {
static int _var = 1;
static int get nextVar => _var++;
Example() {
nextVar++;
// ^^^^^^^
// [analyzer] STATIC_WARNING.ASSIGNMENT_TO_FINAL_NO_SETTER
// [cfe] Setter not found: 'nextVar'.
this.nextVar++;
// ^^^^^^^
// [analyzer] STATIC_TYPE_WARNING.INSTANCE_ACCESS_TO_STATIC_MEMBER
// [cfe] The getter 'nextVar' isn't defined for the class 'Example'.
// ^^^^^^^
// [analyzer] STATIC_WARNING.ASSIGNMENT_TO_FINAL_NO_SETTER
// [cfe] The setter 'nextVar' isn't defined for the class 'Example'.
}
static test() {
nextVar++;
// ^^^^^^^
// [analyzer] STATIC_WARNING.ASSIGNMENT_TO_FINAL_NO_SETTER
// [cfe] Setter not found: 'nextVar'.
this.nextVar++;
// ^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_REFERENCE_TO_THIS
// [cfe] Expected identifier, but got 'this'.
// ^^^^^^^
// [analyzer] STATIC_TYPE_WARNING.INSTANCE_ACCESS_TO_STATIC_MEMBER
// ^^^^^^^
// [analyzer] STATIC_WARNING.ASSIGNMENT_TO_FINAL_NO_SETTER
}
}
class Example1 {
Example1(int i) {}
}
class Example2 extends Example1 {
static int _var = 1;
static int get nextVar => _var++;
Example2() : super(nextVar) {} // No 'this' in scope.
}
void main() {
Example x = new Example();
Example.test();
Example2 x2 = new Example2();
}

View file

@ -0,0 +1,38 @@
// 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.
// Verifies behavior with a static getter, but no field and no setter.
import "package:expect/expect.dart";
class Example {
static int _var = 1;
static int get nextVar => _var++;
Example() {
}
static test() {
}
}
class Example1 {
Example1(int i) {}
}
class Example2 extends Example1 {
static int _var = 1;
static int get nextVar => _var++;
Example2() : super(nextVar) {} // No 'this' in scope.
}
void main() {
Example x = new Example();
Example.test();
Example2 x2 = new Example2();
}

View file

@ -0,0 +1,53 @@
// 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.
// Verifies behavior with a static getter, but no field and no setter.
import "package:expect/expect.dart";
class Example {
static int _var = 1;
static int get nextVar => _var++;
Example() {
nextVar = 1;
// ^^^^^^^
// [analyzer] STATIC_WARNING.ASSIGNMENT_TO_FINAL_NO_SETTER
// [cfe] Setter not found: 'nextVar'.
this.nextVar = 1;
// ^^^^^^^
// [analyzer] STATIC_TYPE_WARNING.INSTANCE_ACCESS_TO_STATIC_MEMBER
// [cfe] The setter 'nextVar' isn't defined for the class 'Example'.
// ^^^^^^^
// [analyzer] STATIC_WARNING.ASSIGNMENT_TO_FINAL_NO_SETTER
}
static test() {
nextVar = 0;
// ^^^^^^^
// [analyzer] STATIC_WARNING.ASSIGNMENT_TO_FINAL_NO_SETTER
// [cfe] Setter not found: 'nextVar'.
this.nextVar = 0;
// ^^^^
// [analyzer] COMPILE_TIME_ERROR.INVALID_REFERENCE_TO_THIS
// [cfe] Expected identifier, but got 'this'.
// ^^^^^^^
// [analyzer] STATIC_TYPE_WARNING.INSTANCE_ACCESS_TO_STATIC_MEMBER
// ^^^^^^^
// [analyzer] STATIC_WARNING.ASSIGNMENT_TO_FINAL_NO_SETTER
}
}
class Example1 {
Example1(int i) {}
}
class Example2 extends Example1 {
static int _var = 1;
static int get nextVar => _var++;
Example2() : super(nextVar) {} // No 'this' in scope.
}
void main() {
Example x = new Example();
Example.test();
Example2 x2 = new Example2();
}

View file

@ -0,0 +1,23 @@
// Copyright (c) 2013, 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.
// Test that we report a compile-time error when an instance getter conflicts
// with an inherited instance method of the same name.
import "package:expect/expect.dart";
class A {
var foo = 42; // //# 00: ok
get foo => 42; // //# 01: ok
foo() => 42; // //# 02: compile-time error
set foo(value) { } // //# 03: ok
}
class B extends A {
get foo => 42;
}
main() {
Expect.equals(42, new B().foo);
}

View file

@ -0,0 +1,26 @@
// Copyright (c) 2016, 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 a getter in a subclass does not shadow the setter in the
// superclass.
import "package:expect/expect.dart";
class A {
int _x = 42;
void set x(int val) {
_x = val;
}
}
class B extends A {
int get x => _x;
}
void main() {
var b = new B();
Expect.equals(42, b.x);
b.x = 21;
Expect.equals(21, b.x);
}

View file

@ -0,0 +1,23 @@
// Copyright (c) 2013, 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.
// Test that we report a compile-time error when a static getter conflicts with
// an inherited instance member of the same name.
import "package:expect/expect.dart";
class A {
var foo = 42; // //# 00: compile-time error
get foo => 42; // //# 01: compile-time error
foo() => 42; // //# 02: compile-time error
set foo(value) { } // //# 03: compile-time error
}
class B extends A {
static get foo => 42;
}
main() {
Expect.equals(42, B.foo);
}

View file

@ -0,0 +1,30 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// Copyright (c) 2013, 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.
//
// Test that a getter has no parameters.
get f1 => null;
get f2
=> null;
get f3
=> null;
get f4
=> null;
get f5
=> null;
main() {
f1;
f2;
f3;
f4;
f5;
}

View file

@ -0,0 +1,39 @@
// Copyright (c) 2013, 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.
//
// Test that a getter has no parameters.
get f1 => null;
get f2
()
// [error line 9, column 1, length 1]
// [analyzer] SYNTACTIC_ERROR.GETTER_WITH_PARAMETERS
// [cfe] A getter can't have formal parameters.
=> null;
get f3
(arg)
// [error line 15, column 1, length 1]
// [analyzer] SYNTACTIC_ERROR.GETTER_WITH_PARAMETERS
// [cfe] A getter can't have formal parameters.
=> null;
get f4
([arg])
// [error line 21, column 1, length 1]
// [analyzer] SYNTACTIC_ERROR.GETTER_WITH_PARAMETERS
// [cfe] A getter can't have formal parameters.
=> null;
get f5
({arg})
// [error line 27, column 1, length 1]
// [analyzer] SYNTACTIC_ERROR.GETTER_WITH_PARAMETERS
// [cfe] A getter can't have formal parameters.
=> null;
main() {
f1;
f2;
f3;
f4;
f5;
}

View file

@ -0,0 +1,94 @@
// 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";
// Tests classes with getters and setters that do not have the same type.
class A {
int a() {
return 37;
}
}
class B extends A {
int b() {
return 38;
}
}
class C {}
class T1 {
late A getterField;
A get field {
// ^^^^^
// [analyzer] STATIC_WARNING.GETTER_NOT_SUBTYPE_SETTER_TYPES
// [cfe] unspecified
return getterField;
}
void set field(B arg) {
getterField = arg;
}
}
class T2 {
late A getterField;
late C setterField;
A get field {
// ^^^^^
// [analyzer] STATIC_WARNING.GETTER_NOT_SUBTYPE_SETTER_TYPES
// [cfe] unspecified
return getterField;
}
// Type C is not assignable to A
void set field(C arg) { setterField = arg; }
}
class T3 {
late B getterField;
B get field {
return getterField;
}
void set field(A arg) {
getterField = arg;
// ^^^
// [analyzer] STATIC_TYPE_WARNING.INVALID_ASSIGNMENT
// [cfe] A value of type 'A' can't be assigned to a variable of type 'B'.
}
}
main() {
T1 instance1 = new T1();
T2 instance2 = new T2();
T3 instance3 = new T3();
instance1.field = new B();
A resultA = instance1.field;
Expect.throwsTypeError(() => instance1.field = new A() as dynamic);
B resultB = instance1.field;
// ^^^^^^^^^^^^^^^
// [analyzer] STATIC_TYPE_WARNING.INVALID_ASSIGNMENT
// ^
// [cfe] A value of type 'A' can't be assigned to a variable of type 'B'.
int result;
result = instance1.field.a();
Expect.equals(37, result);
// Type 'A' has no method named 'b'
instance1.field.b();
// ^
// [analyzer] STATIC_TYPE_WARNING.UNDEFINED_METHOD
// [cfe] The method 'b' isn't defined for the class 'A'.
instance3.field = new B();
result = instance3.field.a();
Expect.equals(37, result);
result = instance3.field.b();
Expect.equals(38, result);
}

View file

@ -0,0 +1,150 @@
// 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 GettersSettersTest {
static int foo = -1;
static testMain() {
A a = new A();
a.x = 2;
Expect.equals(2, a.x);
Expect.equals(2, a.x_);
// Test inheritance.
a = new B();
a.x = 4;
Expect.equals(4, a.x);
Expect.equals(4, a.x_);
// Test overriding.
C c = new C();
c.x = 8;
Expect.equals(8, c.x);
Expect.equals(0, c.x_);
Expect.equals(8, c.y_);
// Test keyed getters and setters.
a.x_ = 0;
Expect.equals(2, a[2]);
a[2] = 4;
Expect.equals(6, a[0]);
// Test assignment operators.
a.x_ = 0;
a[2] += 8;
Expect.equals(12, a[0]);
// Test calling a function that internally uses getters.
Expect.equals(true, a.isXPositive());
// Test static fields.
foo = 42;
Expect.equals(42, foo);
A.foo = 43;
Expect.equals(43, A.foo);
new D().test();
OverrideField of = new OverrideField();
Expect.equals(27, of.getX_());
ReferenceField rf = new ReferenceField();
rf.x_ = 1;
Expect.equals(1, rf.getIt());
rf.setIt(2);
Expect.equals(2, rf.x_);
}
}
class A {
int x_ = -1;
static int foo = -1;
static get bar {
return foo;
}
static set bar(newValue) {
foo = newValue;
}
int get x {
return x_;
}
void set x(int value) {
x_ = value;
}
bool isXPositive() {
return x > 0;
}
int operator [](int index) {
return x_ + index;
}
void operator []=(int index, int value) {
x_ = index + value;
}
int getX_() {
return x_;
}
}
class B extends A {}
class C extends A {
int y_ = -1;
C() : super() {
this.x_ = 0;
}
int get x {
return y_;
}
void set x(int value) {
y_ = value;
}
}
class D extends A {
var x2_;
set x(new_x) {
x2_ = new_x;
}
test() {
x = 87;
Expect.equals(87, x2_);
x = 42;
Expect.equals(42, x2_);
}
}
class OverrideField extends A {
int get x_ {
return 27;
}
}
class ReferenceField extends A {
setIt(a) {
super.x_ = a;
}
int getIt() {
return super.x_;
}
}
main() {
GettersSettersTest.testMain();
}

View file

@ -0,0 +1,10 @@
// 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.
library GetterSetterInLib;
get foo => 42;
set foo(a) {}
get bar => 77;

View file

@ -0,0 +1,7 @@
// Copyright (c) 2015, 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.
library GetterSetterInLib2;
set bar(a) {}

View file

@ -0,0 +1,13 @@
// Copyright (c) 2015, 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.
library GetterSetterInLib3;
var _f = 33;
set bar(a) {
_f = a;
}
get bar => _f;

View file

@ -0,0 +1,24 @@
// 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.
library GetterSetterInLibTest;
import "package:expect/expect.dart";
import 'setter_in_lib.dart';
import 'setter_in_lib2.dart';
import 'setter_in_lib3.dart' as L3;
main() {
Expect.equals(42, foo);
foo = 43;
Expect.equals(42, foo);
Expect.equals(77, bar);
bar = 43;
Expect.equals(77, bar);
Expect.equals(L3.bar, 33);
L3.bar = 44;
Expect.equals(L3.bar, 44);
}

View file

@ -0,0 +1,38 @@
// 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 {
int length = 0;
}
class B {
int length = 0;
foo(receiver) {
length++;
return receiver.length++;
}
bar(receiver) {
++length;
return ++receiver.length;
}
}
main() {
var a = new A();
var b = new B();
var c = <int?>[1, 2, 3];
Expect.equals(3, b.foo(c));
Expect.equals(5, b.bar(c));
Expect.equals(5, c.length);
Expect.equals(0, b.foo(a));
Expect.equals(2, b.bar(a));
Expect.equals(2, a.length);
Expect.equals(4, b.length);
}

View file

@ -0,0 +1,100 @@
// Copyright (c) 2013, 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.
// Test for the evaluation order of getters and setters.
import 'package:expect/expect.dart';
var trace;
class X {
get b {
trace.add('get b');
return new X();
}
set c(value) {
trace.add('set c');
}
toString() {
trace.add('toString');
return 'X';
}
get c {
trace.add('get c');
return 42;
}
get d {
trace.add('get d');
return new X();
}
operator [](index) {
trace.add('index');
return 42;
}
operator []=(index, value) {
trace.add('indexSet');
}
}
main() {
var x = new X();
trace = [];
x.b.c = '$x';
Expect.listEquals(['get b', 'toString', 'set c'], trace);
trace = [];
x.b.c += '$x'.hashCode;
Expect.listEquals(['get b', 'get c', 'toString', 'set c'], trace);
trace = [];
x.b.c++;
Expect.listEquals(['get b', 'get c', 'set c'], trace);
trace = [];
x.b.d[42] = '$x';
Expect.listEquals(['get b', 'get d', 'toString', 'indexSet'], trace);
trace = [];
x.b.d[42] += '$x'.hashCode;
Expect.listEquals(['get b', 'get d', 'index', 'toString', 'indexSet'], trace);
trace = [];
x.b.d[42]++;
Expect.listEquals(['get b', 'get d', 'index', 'indexSet'], trace);
trace = [];
++x.b.d[42];
Expect.listEquals(['get b', 'get d', 'index', 'indexSet'], trace);
trace = [];
x.b.d[x.c] *= '$x'.hashCode;
Expect.listEquals(
['get b', 'get d', 'get c', 'index', 'toString', 'indexSet'], trace);
trace = [];
x.b.c = x.d.c = '$x';
Expect.listEquals([
'get b',
'get d',
'toString',
'set c',
'set c',
], trace);
trace = [];
x.b.c = x.d[42] *= '$x'.hashCode;
Expect.listEquals(
['get b', 'get d', 'index', 'toString', 'indexSet', 'set c'], trace);
trace = [];
x.b.c = ++x.d.c;
Expect.listEquals(['get b', 'get d', 'get c', 'set c', 'set c'], trace);
}

View file

@ -0,0 +1,23 @@
// 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.
// Getters and setters can have different types, and it is not a warning if the
// two types are assignable.
import "package:expect/expect.dart";
int bar = 499;
int get foo => bar;
void set foo(str) {
bar = str.length;
}
main() {
int x = foo;
Expect.equals(499, x);
foo = "1234";
int y = foo;
Expect.equals(4, y);
}

View file

@ -0,0 +1,29 @@
// 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.
// Getters and setters can have different types, but it is a warning if the
// two types are not assignable.
import "package:expect/expect.dart";
int bar = 499;
get foo => bar;
void set foo(
str) {
bar = str.length;
}
main() {
int x = foo;
Expect.equals(499, x);
foo = "1234";
int y = foo;
Expect.equals(4, y);
}

View file

@ -0,0 +1,21 @@
// 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.
// Getters and setters can have different types, but it is a warning if the
// two types are not assignable.
int bar = 499;
int get foo => bar;
// ^^^
// [analyzer] STATIC_WARNING.GETTER_NOT_SUBTYPE_SETTER_TYPES
// [cfe] unspecified
void set foo(String str) {
bar = str.length;
}
main() {
int x = foo;
foo = "1234";
}

View file

@ -0,0 +1,227 @@
// 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.
var get;
var get a;
// [error line 6, column 1, length 3]
// [analyzer] SYNTACTIC_ERROR.VAR_RETURN_TYPE
// [cfe] The return type can't be 'var'.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_FUNCTION_BODY
// [cfe] Expected a function body or '=>'.
var get b, c;
// [error line 13, column 1, length 3]
// [analyzer] SYNTACTIC_ERROR.VAR_RETURN_TYPE
// [cfe] The return type can't be 'var'.
// ^
// [analyzer] SYNTACTIC_ERROR.EXPECTED_EXECUTABLE
// [cfe] Expected '{' before this.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_FUNCTION_BODY
// [cfe] Expected a declaration, but got ','.
// ^
// [cfe] Expected a function body, but got ','.
// ^
// [cfe] Expected a function body, but got '{'.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_CONST_FINAL_VAR_OR_TYPE
// [cfe] Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
var set;
var set d;
// [error line 32, column 1, length 3]
// [analyzer] SYNTACTIC_ERROR.VAR_RETURN_TYPE
// [cfe] The return type can't be 'var'.
// ^
// [analyzer] COMPILE_TIME_ERROR.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER
// [cfe] A function declaration needs an explicit list of parameters.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_FUNCTION_PARAMETERS
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_FUNCTION_BODY
// [cfe] A setter should have exactly one formal parameter.
// ^
// [cfe] Expected a function body or '=>'.
var set e, f;
// [error line 46, column 1, length 3]
// [analyzer] SYNTACTIC_ERROR.VAR_RETURN_TYPE
// [cfe] The return type can't be 'var'.
// ^
// [analyzer] COMPILE_TIME_ERROR.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER
// [cfe] A function declaration needs an explicit list of parameters.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_FUNCTION_PARAMETERS
// ^
// [analyzer] SYNTACTIC_ERROR.EXPECTED_EXECUTABLE
// [cfe] A setter should have exactly one formal parameter.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_FUNCTION_BODY
// [cfe] Expected '{' before this.
// ^
// [cfe] Expected a declaration, but got ','.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_CONST_FINAL_VAR_OR_TYPE
// [cfe] Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
class C0 {
// ^
// [cfe] The non-abstract class 'C0' is missing implementations for these members:
var get;
var get a;
//^^^
// [analyzer] SYNTACTIC_ERROR.VAR_RETURN_TYPE
// [cfe] The return type can't be 'var'.
// ^^^^^^
// [analyzer] STATIC_WARNING.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
var get b, c;
//^^^
// [analyzer] SYNTACTIC_ERROR.VAR_RETURN_TYPE
// [cfe] The return type can't be 'var'.
// ^
// [analyzer] SYNTACTIC_ERROR.EXPECTED_CLASS_MEMBER
// [cfe] Expected '{' before this.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_FUNCTION_BODY
// [cfe] Expected a class member, but got ','.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_CONST_FINAL_VAR_OR_TYPE
// [cfe] Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
var set;
var set d;
//^^^
// [analyzer] SYNTACTIC_ERROR.VAR_RETURN_TYPE
// [cfe] The return type can't be 'var'.
// ^^^^^^
// [analyzer] STATIC_WARNING.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
// ^
// [analyzer] COMPILE_TIME_ERROR.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER
// [cfe] A method declaration needs an explicit list of parameters.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_METHOD_PARAMETERS
// ^
// [cfe] A setter should have exactly one formal parameter.
var set e, f;
//^^^
// [analyzer] SYNTACTIC_ERROR.VAR_RETURN_TYPE
// [cfe] The return type can't be 'var'.
// ^
// [analyzer] COMPILE_TIME_ERROR.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER
// [cfe] A method declaration needs an explicit list of parameters.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_METHOD_PARAMETERS
// ^
// [analyzer] SYNTACTIC_ERROR.EXPECTED_CLASS_MEMBER
// [cfe] A setter should have exactly one formal parameter.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_FUNCTION_BODY
// [cfe] Expected '{' before this.
// ^
// [cfe] Expected a class member, but got ','.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_CONST_FINAL_VAR_OR_TYPE
// [cfe] Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
}
class C1 {
List? get;
List? get a => null;
List? get b, c;
// ^
// [analyzer] SYNTACTIC_ERROR.EXPECTED_CLASS_MEMBER
// [cfe] Expected '{' before this.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_FUNCTION_BODY
// [cfe] Expected a class member, but got ','.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_CONST_FINAL_VAR_OR_TYPE
// [cfe] Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
List? set;
List set d;
//^^^^
// [analyzer] STATIC_WARNING.NON_VOID_RETURN_FOR_SETTER
//^^^^^^^^^^^
// [analyzer] STATIC_WARNING.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
// ^
// [analyzer] COMPILE_TIME_ERROR.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER
// [cfe] A method declaration needs an explicit list of parameters.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_METHOD_PARAMETERS
// ^
// [cfe] A setter should have exactly one formal parameter.
List? set e, f;
//^^^^^
// [analyzer] STATIC_WARNING.NON_VOID_RETURN_FOR_SETTER
// ^
// [analyzer] COMPILE_TIME_ERROR.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER
// [cfe] A method declaration needs an explicit list of parameters.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_METHOD_PARAMETERS
// ^
// [analyzer] SYNTACTIC_ERROR.EXPECTED_CLASS_MEMBER
// [cfe] A setter should have exactly one formal parameter.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_FUNCTION_BODY
// [cfe] Expected '{' before this.
// ^
// [cfe] Expected a class member, but got ','.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_CONST_FINAL_VAR_OR_TYPE
// [cfe] Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
}
class C2 {
List<int>? get;
List<int>? get a => null;
List<int>? get b, c;
// ^
// [analyzer] SYNTACTIC_ERROR.EXPECTED_CLASS_MEMBER
// [cfe] Expected '{' before this.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_FUNCTION_BODY
// [cfe] Expected a class member, but got ','.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_CONST_FINAL_VAR_OR_TYPE
// [cfe] Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
List<int>? set;
List<int> set d;
//^^^^^^^^^
// [analyzer] STATIC_WARNING.NON_VOID_RETURN_FOR_SETTER
//^^^^^^^^^^^^^^^^
// [analyzer] STATIC_WARNING.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
// ^
// [analyzer] COMPILE_TIME_ERROR.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER
// [cfe] A method declaration needs an explicit list of parameters.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_METHOD_PARAMETERS
// ^
// [cfe] A setter should have exactly one formal parameter.
List<int>? set e, f;
//^^^^^^^^^^
// [analyzer] STATIC_WARNING.NON_VOID_RETURN_FOR_SETTER
// ^
// [analyzer] COMPILE_TIME_ERROR.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER
// [cfe] A method declaration needs an explicit list of parameters.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_METHOD_PARAMETERS
// ^
// [analyzer] SYNTACTIC_ERROR.EXPECTED_CLASS_MEMBER
// [cfe] A setter should have exactly one formal parameter.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_FUNCTION_BODY
// [cfe] Expected '{' before this.
// ^
// [cfe] Expected a class member, but got ','.
// ^
// [analyzer] SYNTACTIC_ERROR.MISSING_CONST_FINAL_VAR_OR_TYPE
// [cfe] Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
}
main() {
new C0();
new C1();
new C2();
}

View file

@ -0,0 +1,50 @@
// 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.
var get;
var set;
class C0 {
var get;
var set;
}
class C1 {
List? get;
List? get a => null;
List? set;
}
class C2 {
List<int>? get;
List<int>? get a => null;
List<int>? set;
}
main() {
new C0();
new C1();
new C2();
}

View file

@ -0,0 +1,50 @@
// 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.
class C0 {
}
class C1 {
}
class C2 {
}
main() {
new C0();
new C1();
new C2();
}

View file

@ -0,0 +1,15 @@
// Copyright (c) 2011, 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.
// Verify that an unbound getter is properly resolved at runtime.
class A {
const A();
foo() {
return y; /*@compile-error=unspecified*/
}
}
main() {
new A().foo();
}

View file

@ -5,6 +5,8 @@
// 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]: This test relies on implicit downcasts which are an
// error in NNBD, so has no version in language/.
import "package:expect/expect.dart";
// Tests classes with getters and setters that do not have the same type.

View file

@ -4,6 +4,9 @@
// Getters and setters can have different types, and it is not a warning if the
// two types are assignable.
// [NNBD non-migrated]: NNBD requires a getter's return type to be a subtype of
// the corresponding setter's parameter type. So this test would be a static
// error, and hence there is no corresponding NNBD version.
import "package:expect/expect.dart";
int bar = 499;