| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 | 4 |
| 5 library engine.declaration_resolver_test; | 5 library engine.declaration_resolver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/src/dart/ast/utilities.dart'; | 9 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 } | 29 } |
| 30 | 30 |
| 31 SimpleIdentifier _findSimpleIdentifier( | 31 SimpleIdentifier _findSimpleIdentifier( |
| 32 AstNode root, String code, String search) { | 32 AstNode root, String code, String search) { |
| 33 return EngineTestCase.findNode( | 33 return EngineTestCase.findNode( |
| 34 root, code, search, (n) => n is SimpleIdentifier); | 34 root, code, search, (n) => n is SimpleIdentifier); |
| 35 } | 35 } |
| 36 | 36 |
| 37 @reflectiveTest | 37 @reflectiveTest |
| 38 class DeclarationResolverTest extends ResolverTestCase { | 38 class DeclarationResolverTest extends ResolverTestCase { |
| 39 void fail_visitMethodDeclaration_setter_duplicate() { |
| 40 // https://github.com/dart-lang/sdk/issues/25601 |
| 41 String code = r''' |
| 42 class C { |
| 43 set zzz(x) {} |
| 44 set zzz(y) {} |
| 45 } |
| 46 '''; |
| 47 CompilationUnit unit = resolveSource(code); |
| 48 PropertyAccessorElement firstElement = |
| 49 _findSimpleIdentifier(unit, code, 'zzz(x)').staticElement; |
| 50 PropertyAccessorElement secondElement = |
| 51 _findSimpleIdentifier(unit, code, 'zzz(y)').staticElement; |
| 52 // re-resolve |
| 53 CompilationUnit unit2 = _cloneResolveUnit(unit); |
| 54 SimpleIdentifier firstName = _findSimpleIdentifier(unit2, code, 'zzz(x)'); |
| 55 SimpleIdentifier secondName = _findSimpleIdentifier(unit2, code, 'zzz(y)'); |
| 56 expect(firstName.staticElement, same(firstElement)); |
| 57 expect(secondName.staticElement, same(secondElement)); |
| 58 } |
| 59 |
| 39 @override | 60 @override |
| 40 void setUp() { | 61 void setUp() { |
| 41 super.setUp(); | 62 super.setUp(); |
| 42 } | 63 } |
| 43 | 64 |
| 44 void test_functionDeclaration_getter() { | 65 void test_functionDeclaration_getter() { |
| 45 String code = r''' | 66 String code = r''' |
| 46 int get zzz => 42; | 67 int get zzz => 42; |
| 47 '''; | 68 '''; |
| 48 CompilationUnit unit = resolveSource(code); | 69 CompilationUnit unit = resolveSource(code); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 112 } |
| 92 '''; | 113 '''; |
| 93 CompilationUnit unit = resolveSource(code); | 114 CompilationUnit unit = resolveSource(code); |
| 94 FunctionElement setterElement = | 115 FunctionElement setterElement = |
| 95 _findSimpleIdentifier(unit, code, 'zzz(x)').staticElement; | 116 _findSimpleIdentifier(unit, code, 'zzz(x)').staticElement; |
| 96 // re-resolve | 117 // re-resolve |
| 97 CompilationUnit unit2 = _cloneResolveUnit(unit); | 118 CompilationUnit unit2 = _cloneResolveUnit(unit); |
| 98 SimpleIdentifier setterName = _findSimpleIdentifier(unit2, code, 'zzz(x)'); | 119 SimpleIdentifier setterName = _findSimpleIdentifier(unit2, code, 'zzz(x)'); |
| 99 expect(setterName.staticElement, same(setterElement)); | 120 expect(setterName.staticElement, same(setterElement)); |
| 100 } | 121 } |
| 122 |
| 123 void test_visitMethodDeclaration_getter_duplicate() { |
| 124 String code = r''' |
| 125 class C { |
| 126 int get zzz => 1; |
| 127 String get zzz => null; |
| 128 } |
| 129 '''; |
| 130 CompilationUnit unit = resolveSource(code); |
| 131 PropertyAccessorElement firstElement = |
| 132 _findSimpleIdentifier(unit, code, 'zzz => 1').staticElement; |
| 133 PropertyAccessorElement secondElement = |
| 134 _findSimpleIdentifier(unit, code, 'zzz => null').staticElement; |
| 135 // re-resolve |
| 136 CompilationUnit unit2 = _cloneResolveUnit(unit); |
| 137 SimpleIdentifier firstName = _findSimpleIdentifier(unit2, code, 'zzz => 1'); |
| 138 SimpleIdentifier secondName = |
| 139 _findSimpleIdentifier(unit2, code, 'zzz => null'); |
| 140 expect(firstName.staticElement, same(firstElement)); |
| 141 expect(secondName.staticElement, same(secondElement)); |
| 142 } |
| 143 |
| 144 void test_visitMethodDeclaration_method_duplicate() { |
| 145 String code = r''' |
| 146 class C { |
| 147 void zzz(x) {} |
| 148 void zzz(y) {} |
| 149 } |
| 150 '''; |
| 151 CompilationUnit unit = resolveSource(code); |
| 152 MethodElement firstElement = |
| 153 _findSimpleIdentifier(unit, code, 'zzz(x)').staticElement; |
| 154 MethodElement secondElement = |
| 155 _findSimpleIdentifier(unit, code, 'zzz(y)').staticElement; |
| 156 // re-resolve |
| 157 CompilationUnit unit2 = _cloneResolveUnit(unit); |
| 158 SimpleIdentifier firstName = _findSimpleIdentifier(unit2, code, 'zzz(x)'); |
| 159 SimpleIdentifier secondName = _findSimpleIdentifier(unit2, code, 'zzz(y)'); |
| 160 expect(firstName.staticElement, same(firstElement)); |
| 161 expect(secondName.staticElement, same(secondElement)); |
| 162 } |
| 101 } | 163 } |
| 102 | 164 |
| 103 /** | 165 /** |
| 104 * Strong mode DeclarationResolver tests | 166 * Strong mode DeclarationResolver tests |
| 105 */ | 167 */ |
| 106 @reflectiveTest | 168 @reflectiveTest |
| 107 class StrongModeDeclarationResolverTest extends ResolverTestCase { | 169 class StrongModeDeclarationResolverTest extends ResolverTestCase { |
| 108 @override | 170 @override |
| 109 void setUp() { | 171 void setUp() { |
| 110 resetWithOptions(new AnalysisOptionsImpl()..strongMode = true); | 172 resetWithOptions(new AnalysisOptionsImpl()..strongMode = true); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 expect(element.type.toString(), "<T>(T, T) → T"); | 211 expect(element.type.toString(), "<T>(T, T) → T"); |
| 150 expect(t.element, same(tElement)); | 212 expect(t.element, same(tElement)); |
| 151 | 213 |
| 152 // re-resolve | 214 // re-resolve |
| 153 CompilationUnit unit2 = _cloneResolveUnit(unit); | 215 CompilationUnit unit2 = _cloneResolveUnit(unit); |
| 154 node = _findSimpleIdentifier(unit2, code, 'max').parent; | 216 node = _findSimpleIdentifier(unit2, code, 'max').parent; |
| 155 t = node.typeParameters.typeParameters[0]; | 217 t = node.typeParameters.typeParameters[0]; |
| 156 expect(t.element, same(tElement)); | 218 expect(t.element, same(tElement)); |
| 157 } | 219 } |
| 158 } | 220 } |
| OLD | NEW |