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

Side by Side Diff: pkg/analyzer/test/generated/compile_time_error_code_test.dart

Issue 2335693002: Add support for accessing field formal parameters in the initializer list of constructors (Closed)
Patch Set: Clean up Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 analyzer.test.generated.compile_time_error_code_test; 5 library analyzer.test.generated.compile_time_error_code_test;
6 6
7 import 'package:analyzer/src/generated/engine.dart'; 7 import 'package:analyzer/src/generated/engine.dart';
8 import 'package:analyzer/src/generated/error.dart'; 8 import 'package:analyzer/src/generated/error.dart';
9 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; 9 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode;
10 import 'package:analyzer/src/generated/source_io.dart'; 10 import 'package:analyzer/src/generated/source_io.dart';
(...skipping 1782 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 m() { 1793 m() {
1794 int a; 1794 int a;
1795 int a; 1795 int a;
1796 } 1796 }
1797 }'''); 1797 }''');
1798 computeLibrarySourceErrors(source); 1798 computeLibrarySourceErrors(source);
1799 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1799 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1800 verify([source]); 1800 verify([source]);
1801 } 1801 }
1802 1802
1803 void test_duplicateDefinition_parameters_inConstructor() {
1804 Source source = addSource(r'''
1805 class A {
1806 int a;
1807 A(int a, this.a);
1808 }''');
1809 computeLibrarySourceErrors(source);
1810 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1811 verify([source]);
1812 }
1813
1803 void test_duplicateDefinition_parameters_inFunctionTypeAlias() { 1814 void test_duplicateDefinition_parameters_inFunctionTypeAlias() {
1804 Source source = addSource(r''' 1815 Source source = addSource(r'''
1805 typedef F(int a, double a); 1816 typedef F(int a, double a);
1806 '''); 1817 ''');
1807 computeLibrarySourceErrors(source); 1818 computeLibrarySourceErrors(source);
1808 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]); 1819 assertErrors(source, [CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1809 verify([source]); 1820 verify([source]);
1810 } 1821 }
1811 1822
1812 void test_duplicateDefinition_parameters_inLocalFunction() { 1823 void test_duplicateDefinition_parameters_inLocalFunction() {
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
2145 const A(); 2156 const A();
2146 } 2157 }
2147 class B extends A { 2158 class B extends A {
2148 const B() : super(0); 2159 const B() : super(0);
2149 }'''); 2160 }''');
2150 computeLibrarySourceErrors(source); 2161 computeLibrarySourceErrors(source);
2151 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]); 2162 assertErrors(source, [CompileTimeErrorCode.EXTRA_POSITIONAL_ARGUMENTS]);
2152 verify([source]); 2163 verify([source]);
2153 } 2164 }
2154 2165
2166 void test_fieldFormalParameter_assignedInInitializer() {
2167 Source source = addSource(r'''
2168 class A {
2169 int x;
2170 A(this.x) : x = 3 {}
2171 }''');
2172 computeLibrarySourceErrors(source);
2173 assertErrors(source,
2174 [CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIALIZER]);
2175 verify([source]);
2176 }
2177
2155 void test_fieldInitializedByMultipleInitializers() { 2178 void test_fieldInitializedByMultipleInitializers() {
2156 Source source = addSource(r''' 2179 Source source = addSource(r'''
2157 class A { 2180 class A {
2158 int x; 2181 int x;
2159 A() : x = 0, x = 1 {} 2182 A() : x = 0, x = 1 {}
2160 }'''); 2183 }''');
2161 computeLibrarySourceErrors(source); 2184 computeLibrarySourceErrors(source);
2162 assertErrors(source, 2185 assertErrors(source,
2163 [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]); 2186 [CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZERS]);
2164 verify([source]); 2187 verify([source]);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
2327 verify([source]); 2350 verify([source]);
2328 } 2351 }
2329 2352
2330 void test_finalInitializedMultipleTimes_initializingFormals() { 2353 void test_finalInitializedMultipleTimes_initializingFormals() {
2331 Source source = addSource(r''' 2354 Source source = addSource(r'''
2332 class A { 2355 class A {
2333 final x; 2356 final x;
2334 A(this.x, this.x) {} 2357 A(this.x, this.x) {}
2335 }'''); 2358 }''');
2336 computeLibrarySourceErrors(source); 2359 computeLibrarySourceErrors(source);
2360 // TODO(brianwilkerson) There should only be one error here.
2337 assertErrors(source, [ 2361 assertErrors(source, [
2338 CompileTimeErrorCode.DUPLICATE_DEFINITION, 2362 CompileTimeErrorCode.DUPLICATE_DEFINITION,
2339 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES 2363 CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES
2340 ]); 2364 ]);
2341 verify([source]); 2365 verify([source]);
2342 } 2366 }
2343 2367
2344 void test_finalNotInitialized_instanceField_const_static() { 2368 void test_finalNotInitialized_instanceField_const_static() {
2345 Source source = addSource(r''' 2369 Source source = addSource(r'''
2346 class A { 2370 class A {
(...skipping 4027 matching lines...) Expand 10 before | Expand all | Expand 10 after
6374 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]); 6398 source, [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]);
6375 verify([source]); 6399 verify([source]);
6376 reset(); 6400 reset();
6377 } 6401 }
6378 6402
6379 void _check_wrongNumberOfParametersForOperator1(String name) { 6403 void _check_wrongNumberOfParametersForOperator1(String name) {
6380 _check_wrongNumberOfParametersForOperator(name, ""); 6404 _check_wrongNumberOfParametersForOperator(name, "");
6381 _check_wrongNumberOfParametersForOperator(name, "a, b"); 6405 _check_wrongNumberOfParametersForOperator(name, "a, b");
6382 } 6406 }
6383 } 6407 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/task/options.dart ('k') | pkg/analyzer/test/generated/simple_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698