Migrate language_2/override to NNBD.

Change-Id: Ic9fe9c8e89e3782b754f8404b48c3d27604d76e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150281
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
This commit is contained in:
Robert Nystrom
2020-06-06 00:46:50 +00:00
committed by commit-bot@chromium.org
parent db36f1190f
commit f1a4cc8778
24 changed files with 2372 additions and 0 deletions
@@ -0,0 +1,23 @@
// 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.
// Dart test checking that static/instance field shadowing do not conflict.
import 'package:expect/expect.dart';
class A {
final field;
const A(this.field);
}
class B extends A {
final field;
const B(this.field, fieldA) : super(fieldA);
get fieldA => super.field;
}
main() {
const b = B(1, 2);
Expect.equals(1, b.field);
Expect.equals(2, b.fieldA);
}
@@ -0,0 +1,20 @@
// 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.
/// Overriding field with method.
class A {
var foo;
}
class B extends A {
foo() {}
//^^^
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_METHOD_AND_FIELD
// [cfe] Can't declare a member that conflicts with an inherited one.
}
main() {
B().foo();
}
@@ -0,0 +1,20 @@
// 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.
/// Overriding getter with method.
class A {
get foo => 123;
}
class B extends A {
foo() {}
//^^^
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_METHOD_AND_FIELD
// [cfe] Can't declare a member that conflicts with an inherited one.
}
main() {
B().foo();
}
@@ -0,0 +1,20 @@
// 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.
/// Overriding method with field.
class A {
foo() {}
}
class B extends A {
var foo;
// ^^^
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_FIELD_AND_METHOD
// [cfe] Can't declare a member that conflicts with an inherited one.
}
main() {
B().foo;
}
@@ -0,0 +1,20 @@
// 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.
/// Overriding method with getter.
class A {
foo() => 999;
}
class B extends A {
get foo => 123;
// ^^^
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_FIELD_AND_METHOD
// [cfe] Can't declare a member that conflicts with an inherited one.
}
main() {
B().foo;
}
+19
View File
@@ -0,0 +1,19 @@
// 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.
// Dart test checking that static/instance field shadowing do not conflict.
class A {
int instanceFieldInA = 0;
static int staticFieldInA = 0;
}
class B extends A {
static int instanceFieldInA = 0; // //# 01: compile-time error
int staticFieldInA = 0; // //# 02: ok
static int staticFieldInA = 0; // //# 03: ok
}
main() {
var x = new B();
}
@@ -0,0 +1,69 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// 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.
abstract class A {
method1();
}
abstract class I {
}
abstract class J {
}
class Class extends A implements I, J {
method1() {}
}
main() {
new Class();
}
@@ -0,0 +1,69 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// 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.
abstract class A {
method5();
}
abstract class I {
}
abstract class J {
}
class Class extends A implements I, J {
method5() {}
}
main() {
new Class();
}
@@ -0,0 +1,69 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// 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.
abstract class A {
method6();
}
abstract class I {
}
abstract class J {
}
class Class extends A implements I, J {
method6([a]) {}
}
main() {
new Class();
}
@@ -0,0 +1,69 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// 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.
abstract class A {
method18() {}
}
abstract class I {
method18() {}
}
abstract class J {
}
class Class extends A implements I, J {
}
main() {
new Class();
}
@@ -0,0 +1,69 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// 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.
abstract class A {
method27() {}
}
abstract class I {
}
abstract class J {
}
class Class extends A implements I, J {
method27();
}
main() {
new Class();
}
@@ -0,0 +1,69 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// 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.
abstract class A {
}
abstract class I {
method15() {}
}
abstract class J {
}
class Class extends A implements I, J {
method15() {}
}
main() {
new Class();
}
@@ -0,0 +1,69 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// 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.
abstract class A {
}
abstract class I {
method16() {}
}
abstract class J {
}
class Class extends A implements I, J {
method16([a]) {}
}
main() {
new Class();
}
@@ -0,0 +1,69 @@
// TODO(multitest): This was automatically migrated from a multitest and may
// contain strange or dead code.
// 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.
abstract class A {
}
abstract class I {
}
abstract class J {
}
class Class extends A implements I, J {
}
main() {
new Class();
}
@@ -0,0 +1,75 @@
// 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.
abstract class A {
method1();
method5();
method6();
method7();
get getter8;
set setter9(_);
method10();
get getter11;
set setter12(_);
get field13;
set field14(_);
method18() {}
method27() {}
}
abstract class I {
method10() {}
get getter11 => 0;
set setter12(_) {}
var field13;
var field14;
method15() {}
method16() {}
method17() {}
method18() {}
var member19;
var member20;
var member21;
get member22 => 0;
set member23(_) {}
var member24;
var field25;
var member26;
}
abstract class J {
get member20 => null;
set member20(_) {}
var member21;
}
class Class extends A implements I, J {
// ^^^^^
// [analyzer] STATIC_WARNING.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER
// [cfe] The non-abstract class 'Class' is missing implementations for these members:
method1() {}
method2();
//^^^^^^^^^^
// [analyzer] STATIC_WARNING.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
get getter3;
//^^^^^^^^^^^^
// [analyzer] STATIC_WARNING.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
set setter4(_);
//^^^^^^^^^^^^^^^
// [analyzer] STATIC_WARNING.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER
method5() {}
method6([a]) {}
set field13(_) {}
get field14 => 0;
method15() {}
method16([a]) {}
get member24 => 0;
final field25 = 0;
set member26(_) {}
method27();
}
main() {
new Class();
}
@@ -0,0 +1,127 @@
// 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.
import "package:meta/meta.dart" show virtual;
class A {
get getter1 => null; //# 01: ok
num get getter2 => 0; //# 02: ok
num get getter3 => 0; //# 03: ok
int get getter4 => 0; //# 04: compile-time error
int get getter5 => 0; //# 05: compile-time error
int get getter6 => 0; //# 06: compile-time error
int get getter7 => 0; //# 07: compile-time error
int get getter8 => 0; //# 08: compile-time error
set setter1(_) => null; //# 21: ok
void set setter2(_) {} //# 22: ok
set setter3(_) => null; //# 23: ok
set setter4(_) => null; //# 24: ok
set setter5(num _) => null; //# 25: ok
set setter6(num _) => null; //# 26: compile-time error
set setter7(int _) => null; //# 27: ok
set setter8(int _) => null; //# 28: compile-time error
set setter9(int _) => null; //# 29: compile-time error
set setter10(int _) => null; //# 30: compile-time error
set setter11(int _) => null; //# 31: compile-time error
@virtual int field1 = 0; //# 41: ok
num field2 = 0; //# 42: compile-time error
int field3 = 0; //# 43: compile-time error
int field4 = 0; //# 44: compile-time error
int field5 = 0; //# 45: compile-time error
@virtual num field6 = 0; //# 46: ok
num field7 = 0; //# 47: compile-time error
num get field8 => 0; //# 48: compile-time error
num field9 = 0; //# 49: compile-time error
num field10 = 0; //# 50: compile-time error
set field11(int _) {} //# 51: ok
void set field12(int _) {} //# 52: ok
num field13 = 0; //# 53: compile-time error
set field14(num _) {} //# 54: compile-time error
num field15 = 0; //# 55: ok
}
class B extends A {
num get getter6 => 0; //# 06: continued
set setter9(num _) => null; //# 29: continued
num field5 = 0; //# 45: continued
}
abstract class I {
num get getter7 => 0; //# 07: continued
String get getter8 => ""; //# 08: continued
int get getter9 => 0; //# 09: compile-time error
int get getter10 => 0; //# 10: compile-time error
int get getter11 => 0; //# 11: compile-time error
set setter10(num _) => null; //# 30: continued
set setter11(String _) => null; //# 31: continued
set setter12(int _) => null; //# 32: compile-time error
set setter13(int _) => null; //# 33: compile-time error
set setter13(num _) => null; //# 33a: compile-time error
set setter14(int _) => null; //# 34: compile-time error
}
abstract class J {
String get getter9 => ""; //# 09: continued
num get getter10 => 0; //# 10: continued
num get getter11 => 0; //# 11: continued
set setter12(String _) => null; //# 32: continued
set setter13(num _) => null; //# 33: continued
set setter13(int _) => null; //# 33a: continued
set setter14(num _) => null; //# 34: continued
}
abstract class Class extends B implements I, J {
get getter1 => null; //# 01: continued
num get getter2 => 0; //# 02: continued
int get getter3 => 0; //# 03: continued
num get getter4 => 0; //# 04: continued
double get getter5 => 0.0; //# 05: continued
double get getter6 => 0.0; //# 06: continued
double get getter7 => 0.0; //# 07: continued
double get getter8 => 0.0; //# 08: continued
double get getter9 => 0.0; //# 09: continued
set setter1(_) => null; //# 21: continued
set setter2(_) => null; //# 22: continued
void set setter3(_) {} //# 23: continued
void set setter4(_) {} //# 24: continued
set setter5(num _) => null; //# 25: continued
set setter6(int _) => null; //# 26: continued
set setter7(num _) => null; //# 27: continued
set setter8(double _) => null; //# 28: continued
set setter9(double _) => null; //# 29: continued
set setter10(double _) => null; //# 30: continued
set setter11(double _) => null; //# 31: continued
set setter12(double _) => null; //# 32: continued
int field1 = 0; //# 41: continued
int field2 = 0; //# 42: continued
num field3 = 0; //# 43: continued
double field4 = 0.0; //# 44: continued
double field5 = 0.0; //# 45: continued
int get field6 => 0; //# 46: continued
String get field7 => ""; //# 47: continued
String field8 = ""; //# 48: continued
set field9(int _) {} //# 49: continued
void set field10(int _) {} //# 50: continued
num field11 = 0; //# 51: continued
num field12 = 0; //# 52: continued
set field13(String _) {} //# 53: continued
String field14 = ""; //# 54: continued
set field15(covariant int _) {} //# 55: continued
}
class SubClass extends Class {
double get getter10 => 0.0; //# 10: continued
String get getter11 => ""; //# 11: continued
set setter13(double _) => null; //# 33: continued
set setter13(double _) => null; //# 33a: continued
set setter14(String _) => null; //# 34: continued
}
main() {
new SubClass();
}
@@ -0,0 +1,74 @@
// 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.
class A<T> {
method1(T t) => null; //# 01: ok
method2(T t) => null; //# 02: compile-time error
method4(T t) => null; //# 04: compile-time error
method5(T t) => null; //# 05: ok
method7(T t) => null; //# 07: compile-time error
}
class B<S> extends A
<S> //# 01: continued
<num> //# 02: continued
<S> //# 04: continued
<S> //# 05: continued
{
method1(S s) => null; //# 01: continued
method2(int i) => null; //# 02: continued
method3(S s) => null; //# 03: ok
method4(int i) => null; //# 04: continued
method6(S s) => null; //# 06: compile-time error
}
abstract class I<U> {
method3(U u) => null; //# 03: continued
method6(U u) => null; //# 06: continued
method7(U u) => null; //# 07: continued
method8(U u) => null; //# 08: compile-time error
method9(U u) => null; //# 09: compile-time error
method10(U u) => null; //# 10: compile-time error
}
abstract class J<V> {
method8(V v) => null; //# 08: continued
method9(V v) => null; //# 09: continued
method10(V v) => null; //# 10: continued
}
abstract class Class<W> extends B
<double> //# 03: continued
<W> //# 05: continued
<W> //# 06: continued
<int> //# 07: continued
implements
I
<int> //# 03: continued
<num> //# 06: continued
<String> //# 07: continued
<int> //# 08: continued
<int> //# 09: continued
<int> //# 10: continued
,
J
<String> //# 08: continued
<num> //# 09: continued
<num> //# 10: continued
{
method3(num i) => null; //# 03: continued
method5(W w) => null; //# 05: continued
method6(int i) => null; //# 06: continued
method7(double d) => null; //# 07: continued
method8(double d) => null; //# 08: continued
}
class SubClass extends Class {
method9(double d) => null; //# 09: continued
method10(String s) => null; //# 10: continued
}
main() {
new SubClass();
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,116 @@
// 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.
// Test static warnings for method overrides.
class A {
method1() => null; //# 01: ok
method2(a) => null; //# 02: ok
method3(a, b, c, d) => null; //# 03: ok
method4() => null; //# 04: compile-time error
method6(a, b, c) => null; //# 06: compile-time error
method7([a]) => null; //# 07: ok
method8([a, b]) => null; //# 08: ok
method9([a, b, c]) => null; //# 09: ok
method10([a]) => null; //# 10: ok
method11(a) => null; //# 11: compile-time error
method12(a, [b]) => null; //# 12: compile-time error
method13(a, [b]) => null; //# 13: compile-time error
method14(a, b, [c, d, e]) => null; //# 14: compile-time error
method15({a}) => null; //# 15: ok
method16({a, b}) => null; //# 16: ok
method17({a, b, c}) => null; //# 17: ok
method18(d, {a, b, c}) => null; //# 18: ok
method19({a}) => null; //# 19: compile-time error
method20({a, b}) => null; //# 20: compile-time error
method21({a, b, c, d}) => null; //# 21: compile-time error
method22(int a) => null; //# 22: ok
method23(int a) => null; //# 23: ok
void method24() {} //# 24: ok
method25() => null; //# 25: ok
void method26() {} //# 26: ok
int method27() => 0; //# 27: compile-time error
method28(int a) => null; //# 28: compile-time error
method29(int a) => null; //# 29: compile-time error
method30(int a) => null; //# 30: compile-time error
method34(int a) => null; //# 34: ok
method35(int a) => null; //# 35: ok
method36(int a) => null; //# 36: compile-time error
method37(num a) => null; //# 37: ok
method38(covariant num a) => null; //# 38: ok
method39(num a) => null; //# 39: compile-time error
}
class B extends A {
method28(num a) => null; //# 28: continued
method29(a) => null; //# 29: continued
method34(num a) => null; //# 34: continued
method35(dynamic a) => null; //# 35: continued
method36(dynamic a) => null; //# 36: continued
method37(covariant dynamic a) => null; //# 37: continued
method38(dynamic a) => null; //# 38: continued
method39(covariant dynamic a) => null; //# 39: continued
}
abstract class I {
method5() => null; //# 05: compile-time error
method31(int a) => null; //# 31: compile-time error
method32(int a) => null; //# 32: compile-time error
method33(num a) => null; //# 33: compile-time error
}
abstract class J {
method31(num a) => null; //# 31: continued
method32(double a) => null; //# 32: continued
method33(int a) => null; //# 33: continued
}
class Class extends B implements I, J {
method1() => null; //# 01: continued
method2(b) => null; //# 02: continued
method3(b, a, d, c) => null; //# 03: continued
method4(a) => null; //# 04: continued
method5(a) => null; //# 05: continued
method6(a, b, c, d) => null; //# 06: continued
method7([a]) => null; //# 07: continued
method8([b, a]) => null; //# 08: continued
method9([b, d, a, c]) => null; //# 09: continued
method10([a]) => null; //# 10: continued
method11() => null; //# 11: continued
method12(a) => null; //# 12: continued
method13([a]) => null; //# 13: continued
method14([a, b, c, d]) => null; //# 14: continued
method15({a}) => null; //# 15: continued
method16({b, a}) => null; //# 16: continued
method17({b, c, a, d}) => null; //# 17: continued
method18(e, {b, c, a, d}) => null; //# 18: continued
method19() => null; //# 19: continued
method20({b}) => null; //# 20: continued
method21({a, e, d, c}) => null; //# 21: continued
method22(int a) => null; //# 22: continued
method23(num a) => null; //# 23: continued
method24() => null; //# 24: continued
void method25() {} //# 25: continued
int method26() => 0; //# 26: continued
void method27() {} //# 27: continued
method28(double a) => null; //# 28: continued
method29(String a) => null; //# 29: continued
method30(String a) => null; //# 30: continued
method36(int a) => null; //# 36: continued
method37(int a) => null; //# 37: continued
method38(int a) => null; //# 38: continued
method39(String a) => null; //# 39: continued
}
class SubClass extends Class {
method31(double a) => null; //# 31: continued
method32(String a) => null; //# 32: continued
method33(double a) => null; //# 33: continued
}
main() {
new SubClass();
}
@@ -0,0 +1,42 @@
// 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.
class A {
var member1; //# 01: compile-time error
member2() {} //# 02: compile-time error
get member3 => null; //# 03: compile-time error
member4() {} //# 04: compile-time error
}
abstract class I {
var member5; //# 05: ok
var member6; //# 06: compile-time error
get member7; //# 07: compile-time error
get member8; //# 08: compile-time error
get member9; //# 09: compile-time error
}
abstract class J {
get member5; //# 05: continued
member6() {} //# 06: continued
member7() {} //# 07: continued
member8() {} //# 08: continued
member9() {} //# 09: continued
}
abstract class B extends A implements I, J {}
class Class extends B {
member1() {} //# 01: continued
var member2; //# 02: continued
member3() {} //# 03: continued
get member4 => null; //# 04: continued
var member5; //# 05: continued
member8() {} //# 08: continued
get member9 => null; //# 09: continued
}
main() {
new Class();
}
@@ -0,0 +1,49 @@
// 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 use of noSuchMethod in relation to abstract methods in
// concrete classes.
abstract class A {
method6(); //# 06: compile-time error
method7(); //# 07: compile-time error
method8(); //# 08: ok
}
abstract class I {
method9(); //# 09: compile-time error
method10(); //# 10: compile-time error
method11(); //# 11: ok
}
class Class1 extends A implements I {
method1(); //# 01: compile-time error
noSuchMethod(_) => null; //# 03: ok
method3(); //# 03: continued
noSuchMethod(_, [__]) => null; //# 04: ok
method4(); //# 04: continued
noSuchMethod(_); //# 05: compile-time error
method5(); //# 05: continued
noSuchMethod(_) => null; //# 08: continued
noSuchMethod(_) => null; //# 11: continued
}
class B {
method12(); //# 12: compile-time error
noSuchMethod(_) => null; //# 13: ok
method13(); //# 13: continued
}
class Class2 extends B {}
main() {
new Class1();
new Class2();
}
@@ -0,0 +1,32 @@
main() {
new C();
}
class A {
void set setter1(num x) {} //# 001: compile-time error
void set setter2(num x) {} //# 002: compile-time error
void set setter3(num x) {} //# 003: ok
void set setter4(num x) {} //# 004: compile-time error
void set setter5(num x) {} //# 005: ok
void set setter6(num x) {} //# 006: compile-time error
void set setter7(num x) {} //# 007: ok
}
class B extends A {
void set setter1(covariant dynamic x) {} //# 001: continued
void set setter2(int x) {} //# 002: continued
void set setter3(covariant dynamic x) {} //# 003: continued
void set setter4(dynamic x) {} //# 004: continued
void set setter5(covariant dynamic x) {} //# 005: continued
covariant dynamic setter6; //# 006: continued
covariant dynamic setter7; //# 007: continued
}
class C extends B {
void set setter1(String x) {} //# 001: continued
void set setter3(num x) {} //# 003: continued
void set setter4(int x) {} //# 004: continued
void set setter5(int x) {} //# 005: continued
void set setter6(String x) {} //# 006: continued
void set setter7(int x) {} //# 007: continued
}
@@ -0,0 +1,34 @@
// 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.
import "package:expect/expect.dart";
// Test overriding a method with a field.
class Super {
Super() : super();
instanceMethod() => 42;
}
class Sub extends Super {
Sub() : super();
superInstanceMethod() => super.instanceMethod();
}
main() {
var s = new Sub();
Super sup = s;
Sub sub = s;
print(s.instanceMethod);
Expect.equals(42, s.superInstanceMethod());
Expect.equals(42, sub.superInstanceMethod());
}
@@ -0,0 +1,37 @@
// 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";
// Test overriding a method with a field.
class Super {
Super() : super();
instanceMethod() => 42;
}
class Sub extends Super {
Sub() : super();
var instanceMethod = 87;
// ^^^^^^^^^^^^^^
// [analyzer] COMPILE_TIME_ERROR.CONFLICTING_FIELD_AND_METHOD
// [cfe] Can't declare a member that conflicts with an inherited one.
superInstanceMethod() => super.instanceMethod();
}
main() {
var s = new Sub();
Super sup = s;
Sub sub = s;
print(s.instanceMethod);
Expect.equals(42, s.superInstanceMethod());
Expect.equals(42, sup.superInstanceMethod());
// ^^^^^^^^^^^^^^^^^^^
// [analyzer] STATIC_TYPE_WARNING.UNDEFINED_METHOD
// [cfe] The method 'superInstanceMethod' isn't defined for the class 'Super'.
Expect.equals(42, sub.superInstanceMethod());
}