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

Side by Side Diff: compiler/javatests/com/google/dart/compiler/resolver/ResolverTest.java

Issue 10665018: Issue 2477. Can not reference instance method from initializer (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
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 4
5 package com.google.dart.compiler.resolver; 5 package com.google.dart.compiler.resolver;
6 6
7 import static com.google.dart.compiler.common.ErrorExpectation.errEx;
8
7 import com.google.common.base.Joiner; 9 import com.google.common.base.Joiner;
8 import com.google.dart.compiler.DartCompilationError; 10 import com.google.dart.compiler.DartCompilationError;
9 import com.google.dart.compiler.ErrorCode; 11 import com.google.dart.compiler.ErrorCode;
10 import com.google.dart.compiler.ast.DartClass; 12 import com.google.dart.compiler.ast.DartClass;
11 import com.google.dart.compiler.common.ErrorExpectation; 13 import com.google.dart.compiler.common.ErrorExpectation;
12 import com.google.dart.compiler.type.DynamicType; 14 import com.google.dart.compiler.type.DynamicType;
13 import com.google.dart.compiler.type.InterfaceType; 15 import com.google.dart.compiler.type.InterfaceType;
14 import com.google.dart.compiler.type.Type; 16 import com.google.dart.compiler.type.Type;
15 import com.google.dart.compiler.type.Types; 17 import com.google.dart.compiler.type.Types;
16 18
17 import static com.google.dart.compiler.common.ErrorExpectation.errEx;
18
19 import junit.framework.Assert; 19 import junit.framework.Assert;
20 20
21 import java.util.List; 21 import java.util.List;
22 22
23 /** 23 /**
24 * Basic tests of the resolver. 24 * Basic tests of the resolver.
25 */ 25 */
26 public class ResolverTest extends ResolverTestCase { 26 public class ResolverTest extends ResolverTestCase {
27 private final DartClass object = makeClass("Object", null); 27 private final DartClass object = makeClass("Object", null);
28 private final DartClass array = makeClass("Array", makeType("Object"), "E"); 28 private final DartClass array = makeClass("Array", makeType("Object"), "E");
(...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 errEx(ResolverErrorCode.NAMED_PARAMETERS_CANNOT_START_WITH_UNDER, 2, 15, 4)); 1322 errEx(ResolverErrorCode.NAMED_PARAMETERS_CANNOT_START_WITH_UNDER, 2, 15, 4));
1323 } 1323 }
1324 1324
1325 public void testUndercoreInNamedParameterFunctionAlias() { 1325 public void testUndercoreInNamedParameterFunctionAlias() {
1326 resolveAndTest(Joiner.on("\n").join( 1326 resolveAndTest(Joiner.on("\n").join(
1327 "class Object {}", 1327 "class Object {}",
1328 "typedef Object func([_foo]);"), 1328 "typedef Object func([_foo]);"),
1329 errEx(ResolverErrorCode.NAMED_PARAMETERS_CANNOT_START_WITH_UNDER, 2, 22, 4)); 1329 errEx(ResolverErrorCode.NAMED_PARAMETERS_CANNOT_START_WITH_UNDER, 2, 22, 4));
1330 } 1330 }
1331 1331
1332 /**
1333 * "this" is not accessible to initializers, so invocation of instance method is error.
1334 * <p>
1335 * http://code.google.com/p/dart/issues/detail?id=2477
1336 */
1337 public void test_callInstanceMethod_fromInitializer() throws Exception {
1338 resolveAndTest(
1339 Joiner.on("\n").join(
1340 "// filler filler filler filler filler filler filler filler filler f iller",
1341 "class Object {}",
1342 "class A {",
1343 " var x;",
1344 " A() : x = foo() {}",
1345 " foo() {}",
1346 "}",
1347 ""),
1348 errEx(ResolverErrorCode.INSTANCE_METHOD_FROM_INITIALIZER, 5, 13, 5));
1349 }
1350
1351 /**
1352 * "this" is not accessible to initializers, so reference of instance method i s error.
1353 * <p>
1354 * http://code.google.com/p/dart/issues/detail?id=2477
1355 */
1356 public void test_referenceInstanceMethod_fromInitializer() throws Exception {
1357 resolveAndTest(
1358 Joiner.on("\n").join(
1359 "// filler filler filler filler filler filler filler filler filler f iller",
1360 "class Object {}",
1361 "class A {",
1362 " var x;",
1363 " A() : x = foo {}",
1364 " foo() {}",
1365 "}",
1366 ""),
1367 errEx(ResolverErrorCode.INSTANCE_METHOD_FROM_INITIALIZER, 5, 13, 3)) ;
1368 }
1369
1332 public void testRedirectConstructor() { 1370 public void testRedirectConstructor() {
1333 resolveAndTest(Joiner.on("\n").join( 1371 resolveAndTest(Joiner.on("\n").join(
1334 "class Object {}", 1372 "class Object {}",
1335 "interface int {}", 1373 "interface int {}",
1336 "int topLevel() {}", 1374 "int topLevel() {}",
1337 "class A {", 1375 "class A {",
1338 " method() {}", 1376 " method() {}",
1339 "}", 1377 "}",
1340 "class C {", 1378 "class C {",
1341 " C(arg){}", 1379 " C(arg){}",
1342 " C.named1() : this(topLevel());", // ok 1380 " C.named1() : this(topLevel());", // ok
1343 " C.named2() : this(method());", // error, not a static method 1381 " C.named2() : this(method());", // error, not a static method
1344 " C.named3() : this(new A().method());", // ok 1382 " C.named3() : this(new A().method());", // ok
1345 " method() {}", 1383 " method() {}",
1346 "}"), 1384 "}"),
1347 errEx(ResolverErrorCode.INSTANCE_METHOD_FROM_REDIRECT, 10, 21, 8)); 1385 errEx(ResolverErrorCode.INSTANCE_METHOD_FROM_REDIRECT, 10, 21, 8));
1348 } 1386 }
1349 } 1387 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698