diff --git a/tests/language/prefix/assignment_runtime_test.dart b/tests/language/prefix/assignment_runtime_test.dart new file mode 100644 index 00000000000..c33c8f5b1e5 --- /dev/null +++ b/tests/language/prefix/assignment_runtime_test.dart @@ -0,0 +1,29 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// 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. + +// Validate that assignment to a prefix is handled consistently with the +// following spec text from section 16.19 (Assignment): +// Evaluation of an assignment a of the form v = e proceeds as follows: +// Let d be the innermost declaration whose name is v or v=, if it exists. +// It is a compile-time error if d denotes a prefix object. + +import "empty_library.dart" as p; + +class Base { + var p; +} + +class Derived extends Base { + void f() { + + } +} + +main() { + new Derived().f(); + +} diff --git a/tests/language/prefix/assignment_test.dart b/tests/language/prefix/assignment_test.dart new file mode 100644 index 00000000000..5a32011e7d3 --- /dev/null +++ b/tests/language/prefix/assignment_test.dart @@ -0,0 +1,32 @@ +// 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. + +// Validate that assignment to a prefix is handled consistently with the +// following spec text from section 16.19 (Assignment): +// Evaluation of an assignment a of the form v = e proceeds as follows: +// Let d be the innermost declaration whose name is v or v=, if it exists. +// It is a compile-time error if d denotes a prefix object. + +import "empty_library.dart" as p; + +class Base { + var p; +} + +class Derived extends Base { + void f() { + p = 1; +// ^ +// [analyzer] COMPILE_TIME_ERROR.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT +// [cfe] A prefix can't be used as an expression. + } +} + +main() { + new Derived().f(); + p = 1; +//^ +// [analyzer] COMPILE_TIME_ERROR.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT +// [cfe] A prefix can't be used as an expression. +} diff --git a/tests/language/prefix/empty_library.dart b/tests/language/prefix/empty_library.dart new file mode 100644 index 00000000000..fe101dc999a --- /dev/null +++ b/tests/language/prefix/empty_library.dart @@ -0,0 +1,5 @@ +// 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 empty_library; diff --git a/tests/language/prefix/identifier_reference_test.dart b/tests/language/prefix/identifier_reference_test.dart new file mode 100644 index 00000000000..e59b6fea630 --- /dev/null +++ b/tests/language/prefix/identifier_reference_test.dart @@ -0,0 +1,25 @@ +// 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. + +// Validate the following spec text from section 16.32 (Identifier Reference): +// Evaluation of an identifier expression e of the form id proceeds as +// follows: +// Let d be the innermost declaration in the enclosing lexical scope whose +// name is id or id=. If no such declaration exists in the lexical scope, +// d be the declaration of the inherited member named id if it exists. +// - If d is a prefix p, a compile-time error occurs unless the token +// immediately following d is '.'. + +import "package:expect/expect.dart"; +import "empty_library.dart" as p; + +void f(x) {} + +main() { + f(p); // //# 01: compile-time error + var x = p; // //# 02: compile-time error + var x = p[0]; //# 03: compile-time error + p[0] = null; // //# 04: compile-time error + p += 0; // //# 05: compile-time error +} diff --git a/tests/language/prefix/import_collision_runtime_test.dart b/tests/language/prefix/import_collision_runtime_test.dart new file mode 100644 index 00000000000..e0dc3c08e7e --- /dev/null +++ b/tests/language/prefix/import_collision_runtime_test.dart @@ -0,0 +1,16 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// 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. + +// Using the same prefix name while importing two different libraries is +// not an error but both library1.dart and library2.dart define 'foo' which +// results in a duplicate definition error. +import "../library1.dart" as lib2; // defines 'foo'. +import "../library2.dart" as lib2; // also defines 'foo'. + +main() { + +} diff --git a/tests/language/prefix/import_collision_test.dart b/tests/language/prefix/import_collision_test.dart new file mode 100644 index 00000000000..6ad50cb13ba --- /dev/null +++ b/tests/language/prefix/import_collision_test.dart @@ -0,0 +1,16 @@ +// 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. + +// Using the same prefix name while importing two different libraries is +// not an error but both library1.dart and library2.dart define 'foo' which +// results in a duplicate definition error. +import "../library1.dart" as lib2; // defines 'foo'. +import "../library2.dart" as lib2; // also defines 'foo'. + +main() { + lib2.foo = 1; + // ^^^ + // [analyzer] STATIC_WARNING.AMBIGUOUS_IMPORT + // [cfe] Setter not found: 'foo'. +} diff --git a/tests/language/prefix/invalid_name_runtime_test.dart b/tests/language/prefix/invalid_name_runtime_test.dart new file mode 100644 index 00000000000..a2a71f1c3f6 --- /dev/null +++ b/tests/language/prefix/invalid_name_runtime_test.dart @@ -0,0 +1,13 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// 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. + +// Prefix must be a valid identifier. +import "../library1.dart" + + ; + +main() {} diff --git a/tests/language/prefix/invalid_name_test.dart b/tests/language/prefix/invalid_name_test.dart new file mode 100644 index 00000000000..7ee08b17fe3 --- /dev/null +++ b/tests/language/prefix/invalid_name_test.dart @@ -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. + +// Prefix must be a valid identifier. +import "../library1.dart" + as lib1.invalid + // ^^^^ + // [analyzer] SYNTACTIC_ERROR.EXPECTED_TOKEN + // [cfe] Expected ';' after this. + // ^ + // [analyzer] SYNTACTIC_ERROR.EXPECTED_EXECUTABLE + // [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. + ; + +main() {} diff --git a/tests/language/prefix/new_test.dart b/tests/language/prefix/new_test.dart new file mode 100644 index 00000000000..23c78345306 --- /dev/null +++ b/tests/language/prefix/new_test.dart @@ -0,0 +1,12 @@ +// 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 PrefixTest; + +import "package:expect/expect.dart"; +import "test1.dart"; + +main() { + Expect.equals(Prefix.getSource(), Prefix.getImport() + 1); +} diff --git a/tests/language/prefix/new_test1.dart b/tests/language/prefix/new_test1.dart new file mode 100644 index 00000000000..106de8037e4 --- /dev/null +++ b/tests/language/prefix/new_test1.dart @@ -0,0 +1,19 @@ +// 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 PrefixTest1; + +import "test2.dart" as test2; + +class Prefix { + static const int foo = 43; + + static getSource() { + return foo; + } + + static getImport() { + return test2.Prefix.foo; + } +} diff --git a/tests/language/prefix/new_test2.dart b/tests/language/prefix/new_test2.dart new file mode 100644 index 00000000000..75a5c6e2241 --- /dev/null +++ b/tests/language/prefix/new_test2.dart @@ -0,0 +1,9 @@ +// 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 PrefixNewTest2; + +class Prefix { + static const int foo = 42; +} diff --git a/tests/language/prefix/prefix101_test.dart b/tests/language/prefix/prefix101_test.dart new file mode 100644 index 00000000000..b479e6d7788 --- /dev/null +++ b/tests/language/prefix/prefix101_test.dart @@ -0,0 +1,57 @@ +// 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. + +// Test to check if we are able to import multiple libraries using the +// same prefix. + +library Prefix101Test.dart; + +import "package:expect/expect.dart"; +import "../library10.dart" as lib101; +import "../library11.dart" as lib101; + +class Prefix101Test { + static Test1() { + var result = 0; + var obj = new lib101.Library10(1); + result = obj.fld; + Expect.equals(1, result); + result += obj.func(); + Expect.equals(3, result); + result += lib101.Library10.static_func(); + Expect.equals(6, result); + result += lib101.Library10.static_fld; + Expect.equals(10, result); + } + + static Test2() { + var result = 0; + var obj = new lib101.Library11(4); + result = obj.fld; + Expect.equals(4, result); + result += obj.func(); + Expect.equals(7, result); + result += lib101.Library11.static_func(); + Expect.equals(9, result); + result += lib101.Library11.static_fld; + Expect.equals(10, result); + } + + static Test3() { + Expect.equals(10, lib101.top_level10); + Expect.equals(20, lib101.top_level_func10()); + } + + static Test4() { + Expect.equals(100, lib101.top_level11); + Expect.equals(200, lib101.top_level_func11()); + } +} + +main() { + Prefix101Test.Test1(); + Prefix101Test.Test2(); + Prefix101Test.Test3(); + Prefix101Test.Test4(); +} diff --git a/tests/language/prefix/prefix10_test.dart b/tests/language/prefix/prefix10_test.dart new file mode 100644 index 00000000000..3e0853cc329 --- /dev/null +++ b/tests/language/prefix/prefix10_test.dart @@ -0,0 +1,54 @@ +// 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. + +library Prefix10Test.dart; + +import "package:expect/expect.dart"; +import "../library10.dart" as lib10; +import "../library11.dart" as lib11; + +class Prefix10Test { + static Test1() { + var result = 0; + var obj = new lib10.Library10(1); + result = obj.fld; + Expect.equals(1, result); + result += obj.func(); + Expect.equals(3, result); + result += lib10.Library10.static_func(); + Expect.equals(6, result); + result += lib10.Library10.static_fld; + Expect.equals(10, result); + } + + static Test2() { + var result = 0; + var obj = new lib11.Library11(4); + result = obj.fld; + Expect.equals(4, result); + result += obj.func(); + Expect.equals(7, result); + result += lib11.Library11.static_func(); + Expect.equals(9, result); + result += lib11.Library11.static_fld; + Expect.equals(10, result); + } + + static Test3() { + Expect.equals(10, lib10.top_level10); + Expect.equals(20, lib10.top_level_func10()); + } + + static Test4() { + Expect.equals(100, lib11.top_level11); + Expect.equals(200, lib11.top_level_func11()); + } +} + +main() { + Prefix10Test.Test1(); + Prefix10Test.Test2(); + Prefix10Test.Test3(); + Prefix10Test.Test4(); +} diff --git a/tests/language/prefix/prefix11_test.dart b/tests/language/prefix/prefix11_test.dart new file mode 100644 index 00000000000..ec09c332dde --- /dev/null +++ b/tests/language/prefix/prefix11_test.dart @@ -0,0 +1,55 @@ +// 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. +// + +library Prefix11Test.dart; + +import "package:expect/expect.dart"; +import "../library10.dart"; +import "../library11.dart" as lib11; + +class Prefix11Test { + static Test1() { + var result = 0; + var obj = new Library10(1); + result = obj.fld; + Expect.equals(1, result); + result += obj.func(); + Expect.equals(3, result); + result += Library10.static_func(); + Expect.equals(6, result); + result += Library10.static_fld; + Expect.equals(10, result); + } + + static Test2() { + var result = 0; + var obj = new lib11.Library11(4); + result = obj.fld; + Expect.equals(4, result); + result += obj.func(); + Expect.equals(7, result); + result += lib11.Library11.static_func(); + Expect.equals(9, result); + result += lib11.Library11.static_fld; + Expect.equals(10, result); + } + + static Test3() { + Expect.equals(10, top_level10); + Expect.equals(20, top_level_func10()); + } + + static Test4() { + Expect.equals(100, lib11.top_level11); + Expect.equals(200, lib11.top_level_func11()); + } +} + +main() { + Prefix11Test.Test1(); + Prefix11Test.Test2(); + Prefix11Test.Test3(); + Prefix11Test.Test4(); +} diff --git a/tests/language/prefix/prefix12_test.dart b/tests/language/prefix/prefix12_test.dart new file mode 100644 index 00000000000..5ce98bdb956 --- /dev/null +++ b/tests/language/prefix/prefix12_test.dart @@ -0,0 +1,30 @@ +// 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. +// + +library Prefix12Test.dart; + +import "package:expect/expect.dart"; +import "../library11.dart" as lib11; + +class Prefix12Test { + static Test1() { + var result = 0; + var obj = new lib11.Library11.namedConstructor(10); + result = obj.fld; + Expect.equals(10, result); + } + + static Test2() { + int result = 0; + var obj = new lib11.Library111.namedConstructor(10); + result = obj.fld; + Expect.equals(10, result); + } +} + +main() { + Prefix12Test.Test1(); + Prefix12Test.Test2(); +} diff --git a/tests/language/prefix/prefix14_test.dart b/tests/language/prefix/prefix14_test.dart new file mode 100644 index 00000000000..f9d5c684ad5 --- /dev/null +++ b/tests/language/prefix/prefix14_test.dart @@ -0,0 +1,71 @@ +// 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. +// +// Use qualified symbols at various places. + +library Prefix14Test.dart; + +import "package:expect/expect.dart"; +import "../library12.dart" as lib12; + +typedef lib12.Library12 myFunc(lib12.Library12 param); + +class myInterface implements lib12.Library12Interface { + myInterface(lib12.Library12 this.myfld); + lib12.Library12 addObjects(lib12.Library12 value1, lib12.Library12 value2) { + myfld.fld = (value1.fld + value2.fld + myfld.fld); + return myfld; + } + + lib12.Library12 myfld; +} + +class myClass extends lib12.Library12 { + myClass(int value) : super(value); + static lib12.Library12 func1() { + var i = new lib12.Library12(10); + return i; + } + + static lib12.Library12 func2(lib12.Library12 param) { + return param; + } +} + +class myClass1 { + myClass1(int value) : fld1 = new lib12.Library12(value); + lib12.Library12 fld1; +} + +class myClass2 { + myClass2(lib12.Library12 this.fld2); + lib12.Library12 fld2; +} + +main() { + var o; + o = myClass.func1(); + Expect.equals(2, o.func()); + o = new myClass(10); + Expect.equals(10, o.fld); + + myFunc func = myClass.func2; + Expect.equals(2, func(new lib12.Library12(10)).func()); + Expect.equals(10, func(new lib12.Library12(10)).fld); + + o = new myClass1(100); + Expect.equals(2, o.fld1.func()); + Expect.equals(100, o.fld1.fld); + + o = new myClass2(new lib12.Library12(200)); + Expect.equals(2, o.fld2.func()); + Expect.equals(200, o.fld2.fld); + + o = new myInterface(new lib12.Library12(100)); + Expect.equals(2, o.myfld.func()); + Expect.equals(100, o.myfld.fld); + o = o.addObjects(new lib12.Library12(200), new lib12.Library12(300)); + Expect.equals(2, o.func()); + Expect.equals(600, o.fld); +} diff --git a/tests/language/prefix/prefix15_test.dart b/tests/language/prefix/prefix15_test.dart new file mode 100644 index 00000000000..123ae997530 --- /dev/null +++ b/tests/language/prefix/prefix15_test.dart @@ -0,0 +1,48 @@ +// 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. +// +// Use qualified symbols with generics at various places. + +library Prefix15Test.dart; + +import "package:expect/expect.dart"; +import "../library12.dart" as lib12; + +typedef T myFunc(T param); + +class myInterface + implements lib12.Library12Interface { + myInterface(T this.myfld); + T addObjects(covariant T value1, covariant T value2) { + myfld.fld = (value1.fld + value2.fld + myfld.fld); + return myfld; + } + + T myfld; +} + +class myClass2 { + myClass2(T this.fld2); + T func(T val) => val; + T fld2; +} + +main() { + var o; + o = new myClass2(new lib12.Library12(100)); + myFunc func = o.func; + Expect.equals(2, func(new lib12.Library12(10)).func()); + Expect.equals(10, func(new lib12.Library12(10)).fld); + + o = new myClass2(new lib12.Library12(200)); + Expect.equals(2, o.fld2.func()); + Expect.equals(200, o.fld2.fld); + + o = new myInterface(new lib12.Library12(100)); + Expect.equals(2, o.myfld.func()); + Expect.equals(100, o.myfld.fld); + o = o.addObjects(new lib12.Library12(200), new lib12.Library12(300)); + Expect.equals(2, o.func()); + Expect.equals(600, o.fld); +} diff --git a/tests/language/prefix/prefix16_runtime_test.dart b/tests/language/prefix/prefix16_runtime_test.dart new file mode 100644 index 00000000000..b309ea2a9ae --- /dev/null +++ b/tests/language/prefix/prefix16_runtime_test.dart @@ -0,0 +1,30 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// 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. +// +// Unresolved imported symbols are errors. +// In this test, the function myFunc contains malformed types because +// lib12.Library13 is not resolved. + +import "package:expect/expect.dart"; +import "../library12.dart" as lib12; + +typedef + + myFunc( + + param); +typedef + + myFunc2( + + param, int i); + +main() { + Expect.isTrue(((Object? x) => x) is myFunc); + Expect.isTrue(((Object? x, int y) => x) is myFunc2); + Expect.isFalse(((Object? x, String y) => x) is myFunc2); +} diff --git a/tests/language/prefix/prefix16_test.dart b/tests/language/prefix/prefix16_test.dart new file mode 100644 index 00000000000..874b910bf2f --- /dev/null +++ b/tests/language/prefix/prefix16_test.dart @@ -0,0 +1,39 @@ +// 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. +// +// Unresolved imported symbols are errors. +// In this test, the function myFunc contains malformed types because +// lib12.Library13 is not resolved. + +import "package:expect/expect.dart"; +import "../library12.dart" as lib12; + +typedef + lib12.Library13 +// ^^^^^^^^^^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_CLASS +// [cfe] Type 'lib12.Library13' not found. + myFunc( + lib12.Library13 +// ^^^^^^^^^^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_CLASS +// [cfe] Type 'lib12.Library13' not found. + param); +typedef + lib12.Library13 +// ^^^^^^^^^^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_CLASS +// [cfe] Type 'lib12.Library13' not found. + myFunc2( + lib12.Library13 +// ^^^^^^^^^^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_CLASS +// [cfe] Type 'lib12.Library13' not found. + param, int i); + +main() { + Expect.isTrue(((Object x) => x) is myFunc); + Expect.isTrue(((Object x, int y) => x) is myFunc2); + Expect.isFalse(((Object x, String y) => x) is myFunc2); +} diff --git a/tests/language/prefix/prefix17_test.dart b/tests/language/prefix/prefix17_test.dart new file mode 100644 index 00000000000..9b11ac2aa42 --- /dev/null +++ b/tests/language/prefix/prefix17_test.dart @@ -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. + +library Prefix17Test.dart; + +import "../library12.dart" as lib12; + +class LocalClass { + static int static_fld = 42; +} + +void main() { + var lc1 = new lib12.Library12(5); + lib12.Library12 lc2 = new lib12.Library12(10); + lib12.Library12 lc2m = new lib12.Library12.other(10, 2); + lib12.Library12.static_fld = 43; + //print("${LocalClass.static_fld}, ${lc1.fld}, ${lc2.fld}, ${lc2m.fld}, ${lib12.Library12.static_fld}"); +} diff --git a/tests/language/prefix/prefix21_bad_lib.dart b/tests/language/prefix/prefix21_bad_lib.dart new file mode 100644 index 00000000000..1869a7f2f1e --- /dev/null +++ b/tests/language/prefix/prefix21_bad_lib.dart @@ -0,0 +1,13 @@ +// 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. + +library Prefix21Bad; + +int badFunction(int x) { + return x << 1; +} + +Function get getValue { + return badFunction; +} diff --git a/tests/language/prefix/prefix21_good_lib.dart b/tests/language/prefix/prefix21_good_lib.dart new file mode 100644 index 00000000000..2557726a199 --- /dev/null +++ b/tests/language/prefix/prefix21_good_lib.dart @@ -0,0 +1,13 @@ +// 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. + +library Prefix21Good; + +int goodFunction(int x) { + return x; +} + +Function get getValue { + return goodFunction; +} diff --git a/tests/language/prefix/prefix21_test.dart b/tests/language/prefix/prefix21_test.dart new file mode 100644 index 00000000000..bcaebd11a9e --- /dev/null +++ b/tests/language/prefix/prefix21_test.dart @@ -0,0 +1,14 @@ +// 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. + +library Prefix21; + +import "package:expect/expect.dart"; +import "prefix21_good_lib.dart" as good; +import "prefix21_bad_lib.dart" as bad; + +main() { + Expect.equals(good.getValue(42), 42); + Expect.equals(bad.getValue(42), 84); +} diff --git a/tests/language/prefix/prefix22_runtime_test.dart b/tests/language/prefix/prefix22_runtime_test.dart new file mode 100644 index 00000000000..286256af2cd --- /dev/null +++ b/tests/language/prefix/prefix22_runtime_test.dart @@ -0,0 +1,22 @@ +// 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. +// +// Unresolved symbols should be reported as static type warnings. +// This should not prevent execution. + +library Prefix21NegativeTest.dart; +import "../library12.dart" as lib12; + +class myClass { + myClass( + + p) { } +} + +main() { + new myClass(null); // no dynamic type error when assigning null +} diff --git a/tests/language/prefix/prefix22_test.dart b/tests/language/prefix/prefix22_test.dart new file mode 100644 index 00000000000..e28423d4c0b --- /dev/null +++ b/tests/language/prefix/prefix22_test.dart @@ -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. +// +// Unresolved symbols should be reported as static type warnings. +// This should not prevent execution. + +library Prefix21NegativeTest.dart; +import "../library12.dart" as lib12; + +class myClass { + myClass( + lib12.Library13 +// ^^^^^^^^^^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_CLASS +// [cfe] Type 'lib12.Library13' not found. +// ^ +// [cfe] 'Library13' isn't a type. + p) { } +} + +main() { + new myClass(null); // no dynamic type error when assigning null +} diff --git a/tests/language/prefix/prefix23_runtime_test.dart b/tests/language/prefix/prefix23_runtime_test.dart new file mode 100644 index 00000000000..6ab1736b594 --- /dev/null +++ b/tests/language/prefix/prefix23_runtime_test.dart @@ -0,0 +1,21 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// 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. +// +// Unresolved symbols should be reported as an static type warnings. +// This should not prevent execution. + +library Prefix23Test.dart; + +import "../library12.dart" as lib12; + +class myClass { + final + + fld = null; +} + +main() {} diff --git a/tests/language/prefix/prefix23_test.dart b/tests/language/prefix/prefix23_test.dart new file mode 100644 index 00000000000..ef85f1f7bab --- /dev/null +++ b/tests/language/prefix/prefix23_test.dart @@ -0,0 +1,23 @@ +// 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. +// +// Unresolved symbols should be reported as an static type warnings. +// This should not prevent execution. + +library Prefix23Test.dart; + +import "../library12.dart" as lib12; + +class myClass { + final + lib12.Library13 +// ^^^^^^^^^^^^^^^ +// [analyzer] COMPILE_TIME_ERROR.UNDEFINED_CLASS +// [cfe] Type 'lib12.Library13' not found. +// ^ +// [cfe] 'Library13' isn't a type. + fld = null; +} + +main() {} diff --git a/tests/language/prefix/prefix24_lib1.dart b/tests/language/prefix/prefix24_lib1.dart new file mode 100644 index 00000000000..557ed8452c8 --- /dev/null +++ b/tests/language/prefix/prefix24_lib1.dart @@ -0,0 +1,10 @@ +// 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. + +library prefix24_lib1; + +import "prefix24_lib2.dart" as X; + +// lib1_foo() returns value of bar() in library prefix24_lib2. +lib1_foo() => X.bar(); diff --git a/tests/language/prefix/prefix24_lib2.dart b/tests/language/prefix/prefix24_lib2.dart new file mode 100644 index 00000000000..d4dd5926cda --- /dev/null +++ b/tests/language/prefix/prefix24_lib2.dart @@ -0,0 +1,7 @@ +// 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. + +library prefix24_lib2; + +bar() => "prefix24_lib2_bar"; diff --git a/tests/language/prefix/prefix24_lib3.dart b/tests/language/prefix/prefix24_lib3.dart new file mode 100644 index 00000000000..4490f9b597b --- /dev/null +++ b/tests/language/prefix/prefix24_lib3.dart @@ -0,0 +1,9 @@ +// 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. + +library prefix24_lib3; + +class X { + static bar() => "static method bar of class X"; +} diff --git a/tests/language/prefix/prefix24_test.dart b/tests/language/prefix/prefix24_test.dart new file mode 100644 index 00000000000..1e2f4e6cea4 --- /dev/null +++ b/tests/language/prefix/prefix24_test.dart @@ -0,0 +1,22 @@ +// 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. + +library prefix24_test; + +import "package:expect/expect.dart"; + +// Import a library that contains library prefix X. +import "prefix24_lib1.dart"; + +// Import a library that declares class X. +import "prefix24_lib3.dart"; + +// Check that the library prefix X that is used in library prefix24_lib1 +// remains private to that library and does not collide with class X +// defined in (and imported from) prefix24_lib3; + +main() { + Expect.equals("static method bar of class X", X.bar()); + Expect.equals("prefix24_lib2_bar", lib1_foo()); +} diff --git a/tests/language/prefix/prefix_test.dart b/tests/language/prefix/prefix_test.dart new file mode 100644 index 00000000000..bcecae73b8f --- /dev/null +++ b/tests/language/prefix/prefix_test.dart @@ -0,0 +1,18 @@ +// 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. + +library PrefixTest.dart; + +import "package:expect/expect.dart"; +import "test1.dart"; + +class PrefixTest { + static testMain() { + Expect.equals(Prefix.getSource(), Prefix.getImport() + 1); + } +} + +main() { + PrefixTest.testMain(); +} diff --git a/tests/language/prefix/shadow_runtime_test.dart b/tests/language/prefix/shadow_runtime_test.dart new file mode 100644 index 00000000000..dc83ce3251d --- /dev/null +++ b/tests/language/prefix/shadow_runtime_test.dart @@ -0,0 +1,36 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// 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. + +// Type parameters can shadow a library prefix. + +import "package:expect/expect.dart"; +import "../library10.dart" as T; +import "../library10.dart" as lib10; + +class P { + test() { + + } +} + +main() { + new P().test(); + + { + // Variables in the local scope hide the library prefix. + + var result = 0; + result = lib10.Library10.static_fld; + Expect.equals(4, result); + } + + { + // Shadowing is not an error. + var lib10 = 1; + Expect.equals(2, lib10 + 1); + } +} diff --git a/tests/language/prefix/shadow_test.dart b/tests/language/prefix/shadow_test.dart new file mode 100644 index 00000000000..4a5bdc218c5 --- /dev/null +++ b/tests/language/prefix/shadow_test.dart @@ -0,0 +1,38 @@ +// 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. + +// Type parameters can shadow a library prefix. + +import "package:expect/expect.dart"; +import "../library10.dart" as T; +import "../library10.dart" as lib10; + +class P { + test() { + new T.Library10(10); + // ^ + // [cfe] Method not found: 'T.Library10'. + } +} + +main() { + new P().test(); + + { + // Variables in the local scope hide the library prefix. + var lib10 = 0; + var result = 0; + result = lib10.Library10.static_fld; + // ^^^^^^^^^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_GETTER + // [cfe] The getter 'Library10' isn't defined for the class 'int'. + Expect.equals(4, result); + } + + { + // Shadowing is not an error. + var lib10 = 1; + Expect.equals(2, lib10 + 1); + } +} diff --git a/tests/language/prefix/test1.dart b/tests/language/prefix/test1.dart new file mode 100644 index 00000000000..a9c546c6ed6 --- /dev/null +++ b/tests/language/prefix/test1.dart @@ -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. + +library PrefixTest1.dart; + +import "test2.dart" as prefix; + +class Prefix { + static const int foo = 43; + + static getSource() { + return foo; + } + + static getImport() { + return prefix.Prefix.foo; + } +} diff --git a/tests/language/prefix/test2.dart b/tests/language/prefix/test2.dart new file mode 100644 index 00000000000..8538ca38616 --- /dev/null +++ b/tests/language/prefix/test2.dart @@ -0,0 +1,9 @@ +// 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. + +library PrefixTest2.dart; + +class Prefix { + static const int foo = 42; +} diff --git a/tests/language/prefix/transitive_import_prefix_runtime_test.dart b/tests/language/prefix/transitive_import_prefix_runtime_test.dart new file mode 100644 index 00000000000..7b016cc6381 --- /dev/null +++ b/tests/language/prefix/transitive_import_prefix_runtime_test.dart @@ -0,0 +1,14 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// 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. +import "../library10.dart"; + +main() { + // Library prefixes in the imported libraries should not be visible here. + + + +} diff --git a/tests/language/prefix/transitive_import_prefix_test.dart b/tests/language/prefix/transitive_import_prefix_test.dart new file mode 100644 index 00000000000..9186560f254 --- /dev/null +++ b/tests/language/prefix/transitive_import_prefix_test.dart @@ -0,0 +1,20 @@ +// 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. +import "../library10.dart"; + +main() { + // Library prefixes in the imported libraries should not be visible here. + new lib11.Library11(1); + // ^^^^^^^^^^^^^^^ + // [analyzer] STATIC_WARNING.NEW_WITH_NON_TYPE + // [cfe] Method not found: 'lib11.Library11'. + lib11.Library11.static_func(); +//^^^^^ +// [analyzer] STATIC_WARNING.UNDEFINED_IDENTIFIER +// [cfe] Getter not found: 'lib11'. + lib11.Library11.static_fld; +//^^^^^ +// [analyzer] STATIC_WARNING.UNDEFINED_IDENTIFIER +// [cfe] Getter not found: 'lib11'. +} diff --git a/tests/language/prefix/transitive_import_runtime_test.dart b/tests/language/prefix/transitive_import_runtime_test.dart new file mode 100644 index 00000000000..6c130f676fe --- /dev/null +++ b/tests/language/prefix/transitive_import_runtime_test.dart @@ -0,0 +1,18 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// 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. + +// Symbols in libraries imported by the prefixed library should not be visible. + +import "../library12.dart" as lib12; + +main() { + // Class should not be visible. + + + // Variable should not be visible. + +} diff --git a/tests/language/prefix/transitive_import_test.dart b/tests/language/prefix/transitive_import_test.dart new file mode 100644 index 00000000000..0ae3fa75086 --- /dev/null +++ b/tests/language/prefix/transitive_import_test.dart @@ -0,0 +1,21 @@ +// 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. + +// Symbols in libraries imported by the prefixed library should not be visible. + +import "../library12.dart" as lib12; + +main() { + // Class should not be visible. + new lib12.Library11(1); + // ^^^^^^^^^ + // [analyzer] STATIC_WARNING.NEW_WITH_NON_TYPE + // [cfe] Method not found: 'Library11'. + + // Variable should not be visible. + lib12.top_level11; + // ^^^^^^^^^^^ + // [analyzer] STATIC_TYPE_WARNING.UNDEFINED_PREFIXED_NAME + // [cfe] Getter not found: 'top_level11'. +} diff --git a/tests/language/prefix/unqualified_invocation_runtime_test.dart b/tests/language/prefix/unqualified_invocation_runtime_test.dart new file mode 100644 index 00000000000..0841ed0ee10 --- /dev/null +++ b/tests/language/prefix/unqualified_invocation_runtime_test.dart @@ -0,0 +1,32 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// 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. + +// Validate the following spec text from section 16.14.3 (Unqualified +// invocation): +// An unqualifiedfunction invocation i has the form +// id(a1, ..., an, xn+1 : an+1, ..., xn+k : an+k), +// where id is an identifier. +// If there exists a lexically visible declaration named id, let fid be the +// innermost such declaration. Then: +// - If fid is a prefix object, a compile-time error occurs. + +import "empty_library.dart" as p; + +class Base { + void p() {} +} + +class Derived extends Base { + void f() { + + } +} + +main() { + new Derived().f(); + +} diff --git a/tests/language/prefix/unqualified_invocation_test.dart b/tests/language/prefix/unqualified_invocation_test.dart new file mode 100644 index 00000000000..decb2098d0a --- /dev/null +++ b/tests/language/prefix/unqualified_invocation_test.dart @@ -0,0 +1,35 @@ +// 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. + +// Validate the following spec text from section 16.14.3 (Unqualified +// invocation): +// An unqualifiedfunction invocation i has the form +// id(a1, ..., an, xn+1 : an+1, ..., xn+k : an+k), +// where id is an identifier. +// If there exists a lexically visible declaration named id, let fid be the +// innermost such declaration. Then: +// - If fid is a prefix object, a compile-time error occurs. + +import "empty_library.dart" as p; + +class Base { + void p() {} +} + +class Derived extends Base { + void f() { + p(); +// ^ +// [analyzer] COMPILE_TIME_ERROR.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT +// [cfe] A prefix can't be used as an expression. + } +} + +main() { + new Derived().f(); + p(); +//^ +// [analyzer] COMPILE_TIME_ERROR.PREFIX_IDENTIFIER_NOT_FOLLOWED_BY_DOT +// [cfe] A prefix can't be used as an expression. +} diff --git a/tests/language/prefix/unresolved_class_runtime_test.dart b/tests/language/prefix/unresolved_class_runtime_test.dart new file mode 100644 index 00000000000..17442cc4ca9 --- /dev/null +++ b/tests/language/prefix/unresolved_class_runtime_test.dart @@ -0,0 +1,22 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// 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. + +// Unresolved symbols should be reported as an error. +import "../library12.dart" as lib12; + +class Subclass + +{} + +class Implementer + +{} + +main() { + new Subclass(); + new Implementer(); +} diff --git a/tests/language/prefix/unresolved_class_test.dart b/tests/language/prefix/unresolved_class_test.dart new file mode 100644 index 00000000000..dd46a620ffe --- /dev/null +++ b/tests/language/prefix/unresolved_class_test.dart @@ -0,0 +1,25 @@ +// 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. + +// Unresolved symbols should be reported as an error. +import "../library12.dart" as lib12; + +class Subclass + extends lib12.Library13 + // ^^^^^^^^^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.EXTENDS_NON_CLASS + // [cfe] Type 'lib12.Library13' not found. +{} + +class Implementer + implements lib12.Library13 + // ^^^^^^^^^^^^^^^ + // [analyzer] COMPILE_TIME_ERROR.IMPLEMENTS_NON_CLASS + // [cfe] Type 'lib12.Library13' not found. +{} + +main() { + new Subclass(); + new Implementer(); +} diff --git a/tests/language/prefix/variable_collision_runtime_test.dart b/tests/language/prefix/variable_collision_runtime_test.dart new file mode 100644 index 00000000000..87082c0cdc8 --- /dev/null +++ b/tests/language/prefix/variable_collision_runtime_test.dart @@ -0,0 +1,12 @@ +// TODO(multitest): This was automatically migrated from a multitest and may +// contain strange or dead code. + +// 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. +import "../library10.dart" as lib10; + +// Top level variables cannot shadow library prefixes, they should collide. + + +main() {} diff --git a/tests/language/prefix/variable_collision_test.dart b/tests/language/prefix/variable_collision_test.dart new file mode 100644 index 00000000000..fa19d625498 --- /dev/null +++ b/tests/language/prefix/variable_collision_test.dart @@ -0,0 +1,13 @@ +// 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. +import "../library10.dart" as lib10; +// ^ +// [cfe] 'lib10' is already declared in this scope. + +// Top level variables cannot shadow library prefixes, they should collide. +var lib10; +// ^^^^^ +// [analyzer] COMPILE_TIME_ERROR.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER + +main() {}