OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 package com.google.dart.compiler.type; | 4 package com.google.dart.compiler.type; |
5 | 5 |
6 import com.google.common.base.Joiner; | 6 import com.google.common.base.Joiner; |
7 import com.google.common.collect.Iterables; | 7 import com.google.common.collect.Iterables; |
8 import com.google.common.collect.Lists; | 8 import com.google.common.collect.Lists; |
9 import com.google.common.collect.Maps; | 9 import com.google.common.collect.Maps; |
10 import com.google.dart.compiler.CommandLineOptions.CompilerOptions; | 10 import com.google.dart.compiler.CommandLineOptions.CompilerOptions; |
(...skipping 1471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1482 "interface I {", | 1482 "interface I {", |
1483 " foo([x,y]);", | 1483 " foo([x,y]);", |
1484 "}", | 1484 "}", |
1485 "class C implements I {", | 1485 "class C implements I {", |
1486 " foo([x]) {}", | 1486 " foo([x]) {}", |
1487 "}"); | 1487 "}"); |
1488 assertErrors( | 1488 assertErrors( |
1489 result.getErrors(), | 1489 result.getErrors(), |
1490 errEx(ResolverErrorCode.CANNOT_OVERRIDE_METHOD_NAMED_PARAMS, 5, 3, 3)); | 1490 errEx(ResolverErrorCode.CANNOT_OVERRIDE_METHOD_NAMED_PARAMS, 5, 3, 3)); |
1491 } | 1491 } |
1492 | 1492 |
1493 public void test_metadataOverride_OK_method() throws Exception { | 1493 public void test_metadataOverride_OK_method() throws Exception { |
1494 AnalyzeLibraryResult result = analyzeLibrary( | 1494 AnalyzeLibraryResult result = analyzeLibrary( |
1495 "// filler filler filler filler filler filler filler filler filler fille
r", | 1495 "// filler filler filler filler filler filler filler filler filler fille
r", |
1496 "class A {", | 1496 "class A {", |
1497 " foo() {}", | 1497 " foo() {}", |
1498 "}", | 1498 "}", |
1499 "class B extends A {", | 1499 "class B extends A {", |
1500 " // @override", | 1500 " // @override", |
1501 " foo() {}", | 1501 " foo() {}", |
1502 "}", | 1502 "}", |
1503 ""); | 1503 ""); |
1504 assertErrors(result.getErrors()); | 1504 assertErrors(result.getErrors()); |
1505 } | 1505 } |
1506 | 1506 |
1507 public void test_metadataOverride_Bad_method() throws Exception { | 1507 public void test_metadataOverride_Bad_method() throws Exception { |
1508 AnalyzeLibraryResult result = analyzeLibrary( | 1508 AnalyzeLibraryResult result = analyzeLibrary( |
1509 "// filler filler filler filler filler filler filler filler filler fille
r", | 1509 "// filler filler filler filler filler filler filler filler filler fille
r", |
1510 "class A {", | 1510 "class A {", |
1511 "}", | 1511 "}", |
1512 "class B extends A {", | 1512 "class B extends A {", |
1513 " // @override", | 1513 " // @override", |
1514 " foo() {}", | 1514 " foo() {}", |
1515 "}", | 1515 "}", |
1516 ""); | 1516 ""); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1569 "}", | 1569 "}", |
1570 "class B {", | 1570 "class B {", |
1571 " get field() => 0;", | 1571 " get field() => 0;", |
1572 " static set field(var v) {}", | 1572 " static set field(var v) {}", |
1573 "}", | 1573 "}", |
1574 ""); | 1574 ""); |
1575 assertErrors(result.getErrors(), | 1575 assertErrors(result.getErrors(), |
1576 errEx(ResolverErrorCode.FIELD_GETTER_SETTER_SAME_STATIC, 4, 14, 5), | 1576 errEx(ResolverErrorCode.FIELD_GETTER_SETTER_SAME_STATIC, 4, 14, 5), |
1577 errEx(ResolverErrorCode.FIELD_GETTER_SETTER_SAME_STATIC, 8, 14, 5)); | 1577 errEx(ResolverErrorCode.FIELD_GETTER_SETTER_SAME_STATIC, 8, 14, 5)); |
1578 } | 1578 } |
1579 | 1579 |
1580 /** | 1580 /** |
1581 * <p> | 1581 * <p> |
1582 * http://code.google.com/p/dart/issues/detail?id=380 | 1582 * http://code.google.com/p/dart/issues/detail?id=380 |
1583 */ | 1583 */ |
1584 public void test_setterGetterDifferentType() throws Exception { | 1584 public void test_setterGetterDifferentType() throws Exception { |
1585 AnalyzeLibraryResult result = | 1585 AnalyzeLibraryResult result = |
1586 analyzeLibrary( | 1586 analyzeLibrary( |
1587 "// filler filler filler filler filler filler filler filler filler f
iller", | 1587 "// filler filler filler filler filler filler filler filler filler f
iller", |
1588 "class A {} ", | 1588 "class A {} ", |
1589 "class B extends A {}", | 1589 "class B extends A {}", |
(...skipping 1317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2907 "}", | 2907 "}", |
2908 "class C extends A implements Interface<int> {", | 2908 "class C extends A implements Interface<int> {", |
2909 " int m() => 0;", | 2909 " int m() => 0;", |
2910 "}"); | 2910 "}"); |
2911 assertErrors( | 2911 assertErrors( |
2912 libraryResult.getErrors(), | 2912 libraryResult.getErrors(), |
2913 errEx(TypeErrorCode.CANNOT_OVERRIDE_METHOD_NOT_SUBTYPE, 8, 7, 1), | 2913 errEx(TypeErrorCode.CANNOT_OVERRIDE_METHOD_NOT_SUBTYPE, 8, 7, 1), |
2914 errEx(TypeErrorCode.INCOMPATIBLE_TYPES_IN_HIERARCHY, 7, 7, 1)); | 2914 errEx(TypeErrorCode.INCOMPATIBLE_TYPES_IN_HIERARCHY, 7, 7, 1)); |
2915 } | 2915 } |
2916 | 2916 |
| 2917 public void test_variableUsedAsType() throws Exception { |
| 2918 AnalyzeLibraryResult libraryResult = analyzeLibrary( |
| 2919 "// filler filler filler filler filler filler filler filler filler fille
r", |
| 2920 "var func;", |
| 2921 "func i;"); |
| 2922 assertErrors( |
| 2923 libraryResult.getErrors(), |
| 2924 errEx(TypeErrorCode.NOT_A_TYPE, 3, 1, 4)); |
| 2925 } |
| 2926 |
2917 private static <T extends DartNode> T findNode( | 2927 private static <T extends DartNode> T findNode( |
2918 AnalyzeLibraryResult libraryResult, | 2928 AnalyzeLibraryResult libraryResult, |
2919 final Class<T> clazz, | 2929 final Class<T> clazz, |
2920 String pattern) { | 2930 String pattern) { |
2921 final int index = libraryResult.source.indexOf(pattern); | 2931 final int index = libraryResult.source.indexOf(pattern); |
2922 assertTrue(index != -1); | 2932 assertTrue(index != -1); |
2923 final AtomicReference<T> result = new AtomicReference<T>(); | 2933 final AtomicReference<T> result = new AtomicReference<T>(); |
2924 Iterator<DartUnit> unitsIterator = libraryResult.getLibraryUnitResult().getU
nits().iterator(); | 2934 Iterator<DartUnit> unitsIterator = libraryResult.getLibraryUnitResult().getU
nits().iterator(); |
2925 unitsIterator.next(); | 2935 unitsIterator.next(); |
2926 DartUnit unit = unitsIterator.next(); | 2936 DartUnit unit = unitsIterator.next(); |
2927 unit.accept(new ASTVisitor<Void>() { | 2937 unit.accept(new ASTVisitor<Void>() { |
2928 @Override | 2938 @Override |
2929 @SuppressWarnings("unchecked") | 2939 @SuppressWarnings("unchecked") |
2930 public Void visitNode(DartNode node) { | 2940 public Void visitNode(DartNode node) { |
2931 SourceInfo sourceInfo = node.getSourceInfo(); | 2941 SourceInfo sourceInfo = node.getSourceInfo(); |
2932 if (sourceInfo.getOffset() <= index | 2942 if (sourceInfo.getOffset() <= index |
2933 && index < sourceInfo.getEnd() | 2943 && index < sourceInfo.getEnd() |
2934 && clazz.isInstance(node)) { | 2944 && clazz.isInstance(node)) { |
2935 result.set((T) node); | 2945 result.set((T) node); |
2936 } | 2946 } |
2937 return super.visitNode(node); | 2947 return super.visitNode(node); |
2938 } | 2948 } |
2939 }); | 2949 }); |
2940 return result.get(); | 2950 return result.get(); |
2941 } | 2951 } |
2942 } | 2952 } |
OLD | NEW |