Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(714)

Unified Diff: tests/compiler/dart2js/type_checker_test.dart

Issue 25698003: Implement lookupMember for type variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments, add tests. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/typechecker.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/type_checker_test.dart
diff --git a/tests/compiler/dart2js/type_checker_test.dart b/tests/compiler/dart2js/type_checker_test.dart
index 95c0e0d3791988b0cf959a8c9573c7a24cc0776d..ca31c6a077c294ac05fd5baa8cdbb1e16b642262 100644
--- a/tests/compiler/dart2js/type_checker_test.dart
+++ b/tests/compiler/dart2js/type_checker_test.dart
@@ -52,6 +52,11 @@ main() {
testOperatorsAssignability,
testFieldInitializers,
testTypeVariableExpressions,
+ testTypeVariableLookup1,
+ testTypeVariableLookup2,
+ testTypeVariableLookup3,
+ testFunctionTypeLookup,
+ testTypedefLookup,
testTypeLiteral,
testInitializers];
for (Function test in tests) {
@@ -1074,6 +1079,121 @@ void testTypeVariableExpressions() {
analyzeIn(method, "{ T + 1; }", MessageKind.OPERATOR_NOT_FOUND);
}
+void testTypeVariableLookup1() {
+ String script = """
+class Foo {
+ int field;
+ void method(int argument) {}
+ int operator +(Foo foo) {}
+ int get getter => 21;
+}
+
+class Test<S extends Foo, T> {
+ S s;
+ T t;
+ test() {}
+}
+""";
+
+ LibraryElement library = mockLibrary(compiler, script);
+ compiler.parseScript(script, library);
+ ClassElement classTest = library.find(const SourceString("Test"));
+ classTest.ensureResolved(compiler);
+ FunctionElement methodTest =
+ classTest.lookupLocalMember(const SourceString("test"));
+
+ test(String expression, [message]) {
+ analyzeIn(methodTest, "{ $expression; }", message);
+ }
+
+ test('s.field');
+ test('s.method(1)');
+ test('s + s');
+ test('s.getter');
+
+ test('t.toString');
+ test('t.field', MEMBER_NOT_FOUND);
+ test('t.method(1)', MessageKind.METHOD_NOT_FOUND);
+ test('t + t', MessageKind.OPERATOR_NOT_FOUND);
+ test('t.getter', MEMBER_NOT_FOUND);
+
+ test('s.field = "hest"', NOT_ASSIGNABLE);
+ test('s.method("hest")', NOT_ASSIGNABLE);
+ test('s + "hest"', NOT_ASSIGNABLE);
+ test('String v = s.getter', NOT_ASSIGNABLE);
+}
+
+void testTypeVariableLookup2() {
+ String script = """
+class Foo {
+ int field;
+ void method(int argument) {}
+ int operator +(Foo foo) {}
+ int get getter => 21;
+}
+
+class Test<S extends T, T extends Foo> {
+ S s;
+ test() {}
+}""";
+
+ LibraryElement library = mockLibrary(compiler, script);
+ compiler.parseScript(script, library);
+ ClassElement classTest = library.find(const SourceString("Test"));
+ classTest.ensureResolved(compiler);
+ FunctionElement methodTest =
+ classTest.lookupLocalMember(const SourceString("test"));
+
+ test(String expression, [message]) {
+ analyzeIn(methodTest, "{ $expression; }", message);
+ }
+
+ test('s.field');
+ test('s.method(1)');
+ test('s + s');
+ test('s.getter');
+}
+
+void testTypeVariableLookup3() {
+ String script = """
+class Test<S extends T, T extends S> {
+ S s;
+ test() {}
+}""";
+
+ LibraryElement library = mockLibrary(compiler, script);
+ compiler.parseScript(script, library);
+ ClassElement classTest = library.find(const SourceString("Test"));
+ classTest.ensureResolved(compiler);
+ FunctionElement methodTest =
+ classTest.lookupLocalMember(const SourceString("test"));
+
+ test(String expression, [message]) {
+ analyzeIn(methodTest, "{ $expression; }", message);
+ }
+
+ test('s.toString');
+ test('s.field', MEMBER_NOT_FOUND);
+ test('s.method(1)', MessageKind.METHOD_NOT_FOUND);
+ test('s + s', MessageKind.OPERATOR_NOT_FOUND);
+ test('s.getter', MEMBER_NOT_FOUND);
+}
+
+void testFunctionTypeLookup() {
+ analyze('(int f(int)) => f.toString;');
+ analyze('(int f(int)) => f.toString();');
+ analyze('(int f(int)) => f.foo;', MEMBER_NOT_FOUND);
+ analyze('(int f(int)) => f.foo();', MessageKind.METHOD_NOT_FOUND);
+}
+
+void testTypedefLookup() {
+ compiler.parseScript("typedef int F(int);");
+ analyze('(F f) => f.toString;');
+ analyze('(F f) => f.toString();');
+ analyze('(F f) => f.foo;', MEMBER_NOT_FOUND);
+ analyze('(F f) => f.foo();', MessageKind.METHOD_NOT_FOUND);
+}
+
void testTypeLiteral() {
final String source = r"""class Class {
static var field = null;
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/typechecker.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698