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

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

Issue 1073983003: Make invalid to override method names for local nested functions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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
Index: tests/compiler/dart2js/resolver_test.dart
diff --git a/tests/compiler/dart2js/resolver_test.dart b/tests/compiler/dart2js/resolver_test.dart
index 488bf26844f2c48ac8ff27b584d58685aee84e61..5f3a47215758034c85154d294eafbc5416ae0303 100644
--- a/tests/compiler/dart2js/resolver_test.dart
+++ b/tests/compiler/dart2js/resolver_test.dart
@@ -88,6 +88,7 @@ main() {
testOverrideHashCodeCheck,
testSupertypeOrder,
testConstConstructorAndNonFinalFields,
+ testCantAssignMethods,
], (f) => f()));
}
@@ -1142,3 +1143,98 @@ testConstConstructorAndNonFinalFields() {
MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD]);
}));
}
+
+testCantAssignMethods() {
+ checkWarningOn(String script, List<String> errorLocations) {
+ asyncTest(() => compileScript(script).then((compiler) {
+ Expect.equals(0, compiler.errors.length);
+ Expect.equals(errorLocations.length, compiler.warnings.length);
+ for (var i = 0; i < errorLocations.length; i++) {
+ Expect.equals(MessageKind.ASSIGNING_METHOD,
+ compiler.warnings[i].message.kind);
+ Expect.equals(script.indexOf(errorLocations[i]),
+ compiler.warnings[i].node.getBeginToken().charOffset);
+ }
+ }));
+ }
+
+ // Can't override local functions
+ checkWarningOn('''
+ main() {
+ mname() { mname = 2; };
+ mname();
+ }
+ ''', ['mname = 2']);
+
+ checkWarningOn('''
+ main() {
+ mname() { };
+ mname = 3;
+ }
+ ''', ['mname = 3']);
+
+ // Can't override top-level functions
+ checkWarningOn('''
+ m() {}
+ main() { m = 4; }
+ ''', ['m = 4']);
+
+ // Can't override instance methods
+ checkWarningOn('''
+ main() { new B().bar(); }
+ class B {
+ mname() {}
+ bar() {
+ mname = () => null;
+ }
+ }
+ ''', ['mname = () => null']);
+
+ // Can't override super methods
+ checkWarningOn('''
+ main() { new B().bar(); }
+ class A {
+ mname() {}
+ }
+ class B extends A {
+ bar() {
+ super.mname = () => 6;
+ }
+ }
+ ''', ['mname = () => 6']);
+
+ // But fields are OK:
+ checkWarningOn('''
+ main() { new B().bar(); }
+ class A {
+ int fname;
+ }
+ class B extends A {
+ bar() {
+ super.fname = 3;
+ }
+ }
+ ''', []);
+
+ // And we shouldn't confuse index operators either:
+ checkWarningOn('''
+ main() { new B().bar(); }
+ class B {
+ operator[]=(x, y) {}
+ bar() {
+ this[1] = 3; // This is OK
+ }
+ }
+ ''', []);
+ checkWarningOn('''
+ main() { new B().bar(); }
+ class A {
+ operator[]=(x, y) {}
+ }
+ class B extends A {
+ bar() {
+ super[1] = 3; // This is OK
+ }
+ }
+ ''', []);
+}
« pkg/compiler/lib/src/resolution/members.dart ('K') | « pkg/compiler/lib/src/resolution/members.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698