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

Unified Diff: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java

Issue 10442018: Issue 3209. Mark assignment to final field as error (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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: compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
index 5e24f62a3771f7cf24fc70867ac28103e29365ca..abb385512d21c5e0502daecc471a7f6fd41a8405 100644
--- a/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
+++ b/compiler/javatests/com/google/dart/compiler/type/TypeAnalyzerCompilerTest.java
@@ -794,6 +794,49 @@ public class TypeAnalyzerCompilerTest extends CompilerTestCase {
assertErrors(libraryResult.getTypeErrors());
}
+ public void test_finalField_inClass() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ getName(),
+ makeCode(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "class A {",
+ " final f;",
+ "}",
+ "main() {",
+ " A a = new A();",
+ " a.f = 0;", // 6: ERR, is final
+ " a.f += 1;", // 7: ERR, is final
+ " print(a.f);", // 8: OK, can read
+ "}"));
+ assertErrors(
+ libraryResult.getTypeErrors(),
+ errEx(TypeErrorCode.FIELD_IS_FINAL, 7, 5, 1),
+ errEx(TypeErrorCode.FIELD_IS_FINAL, 8, 5, 1));
+ }
+
+ public void test_finalField_inInterface() throws Exception {
+ AnalyzeLibraryResult libraryResult = analyzeLibrary(
+ getName(),
+ makeCode(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "interface I default A {",
+ " final f;",
+ "}",
+ "class A implements I {",
+ " var f;",
+ "}",
+ "main() {",
+ " I a = new I();",
+ " a.f = 0;", // 6: ERR, is final
+ " a.f += 1;", // 7: ERR, is final
+ " print(a.f);", // 8: OK, can read
+ "}"));
+ assertErrors(
+ libraryResult.getTypeErrors(),
+ errEx(TypeErrorCode.FIELD_IS_FINAL, 10, 5, 1),
+ errEx(TypeErrorCode.FIELD_IS_FINAL, 11, 5, 1));
+ }
+
/**
* Test for variants of {@link DartMethodDefinition} return types.
*/

Powered by Google App Engine
This is Rietveld 408576698