Skip to content

Commit b040d3c

Browse files
Improve error message on ambiguous constructors
Fixes #34515 Change-Id: Ibbecab411515309db9f45f7b59283f54d878223a Reviewed-on: https://dart-review.googlesource.com/c/92261 Auto-Submit: Peter von der Ahé <[email protected]> Commit-Queue: Kevin Millikin <[email protected]> Reviewed-by: Kevin Millikin <[email protected]>
1 parent c591454 commit b040d3c

11 files changed

+303
-0
lines changed

pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,6 +3524,12 @@ abstract class BodyBuilder extends ScopeListener<JumpTarget>
35243524
} else {
35253525
errorName ??= debugName(type.name, name);
35263526
}
3527+
} else if (type is InvalidTypeBuilder<TypeBuilder, Object>) {
3528+
LocatedMessage message = type.message;
3529+
return evaluateArgumentsBefore(
3530+
arguments,
3531+
buildProblem(message.messageObject, nameToken.charOffset,
3532+
nameToken.lexeme.length));
35273533
} else {
35283534
errorName = debugName(getNodeName(type), name);
35293535
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
import "issue34515_lib1.dart";
6+
import "issue34515_lib2.dart";
7+
8+
void test() {
9+
ImportedClass(1);
10+
ImportedClass("a");
11+
}
12+
13+
main() {}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Object:
2+
superclasses:
3+
interfaces:
4+
classMembers:
5+
Object._haveSameRuntimeType
6+
Object.toString
7+
Object.runtimeType
8+
Object._toString
9+
Object._simpleInstanceOf
10+
Object._hashCodeRnd
11+
Object._instanceOf
12+
Object.noSuchMethod
13+
Object._objectHashCode
14+
Object._identityHashCode
15+
Object.hashCode
16+
Object._simpleInstanceOfFalse
17+
Object._simpleInstanceOfTrue
18+
Object.==
19+
classSetters:
20+
21+
ImportedClass:
22+
superclasses:
23+
Object
24+
interfaces:
25+
classMembers:
26+
Object.toString
27+
Object.runtimeType
28+
Object._simpleInstanceOf
29+
Object._instanceOf
30+
Object.noSuchMethod
31+
Object._identityHashCode
32+
Object.hashCode
33+
Object._simpleInstanceOfFalse
34+
Object._simpleInstanceOfTrue
35+
Object.==
36+
classSetters:
37+
38+
ImportedClass:
39+
superclasses:
40+
Object
41+
interfaces:
42+
classMembers:
43+
Object.toString
44+
Object.runtimeType
45+
Object._simpleInstanceOf
46+
Object._instanceOf
47+
Object.noSuchMethod
48+
Object._identityHashCode
49+
Object.hashCode
50+
Object._simpleInstanceOfFalse
51+
Object._simpleInstanceOfTrue
52+
Object.==
53+
classSetters:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/issue34515.dart:9:3: Warning: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
6+
// ImportedClass(1);
7+
// ^^^^^^^^^^^^^
8+
//
9+
// pkg/front_end/testcases/issue34515.dart:10:3: Warning: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
10+
// ImportedClass("a");
11+
// ^^^^^^^^^^^^^
12+
//
13+
import self as self;
14+
import "dart:core" as core;
15+
16+
import "org-dartlang-testcase:///issue34515_lib1.dart";
17+
import "org-dartlang-testcase:///issue34515_lib2.dart";
18+
19+
static method test() → void {
20+
let final core::Object #t1 = 1 in invalid-expression "pkg/front_end/testcases/issue34515.dart:9:3: Error: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
21+
ImportedClass(1);
22+
^^^^^^^^^^^^^";
23+
let final core::Object #t2 = "a" in invalid-expression "pkg/front_end/testcases/issue34515.dart:10:3: Error: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
24+
ImportedClass(\"a\");
25+
^^^^^^^^^^^^^";
26+
}
27+
static method main() → dynamic {}
28+
29+
library;
30+
import self as self2;
31+
import "dart:core" as core;
32+
33+
class ImportedClass extends core::Object {
34+
constructor •(core::int a) → self2::ImportedClass
35+
: super core::Object::•()
36+
;
37+
}
38+
39+
library;
40+
import self as self3;
41+
import "dart:core" as core;
42+
43+
class ImportedClass extends core::Object {
44+
constructor •(core::String a) → self3::ImportedClass
45+
: super core::Object::•()
46+
;
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/issue34515.dart:9:3: Warning: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
6+
// ImportedClass(1);
7+
// ^^^^^^^^^^^^^
8+
//
9+
// pkg/front_end/testcases/issue34515.dart:10:3: Warning: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
10+
// ImportedClass("a");
11+
// ^^^^^^^^^^^^^
12+
//
13+
import self as self;
14+
import "dart:core" as core;
15+
16+
import "org-dartlang-testcase:///issue34515_lib1.dart";
17+
import "org-dartlang-testcase:///issue34515_lib2.dart";
18+
19+
static method test() → void {
20+
let final core::Object #t1 = 1 in invalid-expression "pkg/front_end/testcases/issue34515.dart:9:3: Error: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
21+
ImportedClass(1);
22+
^^^^^^^^^^^^^";
23+
let final core::Object #t2 = "a" in invalid-expression "pkg/front_end/testcases/issue34515.dart:10:3: Error: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
24+
ImportedClass(\"a\");
25+
^^^^^^^^^^^^^";
26+
}
27+
static method main() → dynamic {}
28+
29+
library;
30+
import self as self2;
31+
import "dart:core" as core;
32+
33+
class ImportedClass extends core::Object {
34+
constructor •(core::int a) → self2::ImportedClass
35+
: super core::Object::•()
36+
;
37+
}
38+
39+
library;
40+
import self as self3;
41+
import "dart:core" as core;
42+
43+
class ImportedClass extends core::Object {
44+
constructor •(core::String a) → self3::ImportedClass
45+
: super core::Object::•()
46+
;
47+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
library;
2+
import self as self;
3+
4+
import "org-dartlang-testcase:///issue34515_lib1.dart";
5+
import "org-dartlang-testcase:///issue34515_lib2.dart";
6+
7+
static method test() → void
8+
;
9+
static method main() → dynamic
10+
;
11+
12+
library;
13+
import self as self2;
14+
import "dart:core" as core;
15+
16+
class ImportedClass extends core::Object {
17+
constructor •(core::int a) → self2::ImportedClass
18+
;
19+
}
20+
21+
library;
22+
import self as self3;
23+
import "dart:core" as core;
24+
25+
class ImportedClass extends core::Object {
26+
constructor •(core::String a) → self3::ImportedClass
27+
;
28+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/issue34515.dart:9:3: Error: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
6+
// ImportedClass(1);
7+
// ^^^^^^^^^^^^^
8+
//
9+
// pkg/front_end/testcases/issue34515.dart:10:3: Error: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
10+
// ImportedClass("a");
11+
// ^^^^^^^^^^^^^
12+
//
13+
import self as self;
14+
import "dart:core" as core;
15+
16+
import "org-dartlang-testcase:///issue34515_lib1.dart";
17+
import "org-dartlang-testcase:///issue34515_lib2.dart";
18+
19+
static method test() → void {
20+
let final core::Object #t1 = 1 in invalid-expression "pkg/front_end/testcases/issue34515.dart:9:3: Error: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
21+
ImportedClass(1);
22+
^^^^^^^^^^^^^";
23+
let final core::Object #t2 = "a" in invalid-expression "pkg/front_end/testcases/issue34515.dart:10:3: Error: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
24+
ImportedClass(\"a\");
25+
^^^^^^^^^^^^^";
26+
}
27+
static method main() → dynamic {}
28+
29+
library;
30+
import self as self2;
31+
import "dart:core" as core;
32+
33+
class ImportedClass extends core::Object {
34+
constructor •(core::int a) → self2::ImportedClass
35+
: super core::Object::•()
36+
;
37+
}
38+
39+
library;
40+
import self as self3;
41+
import "dart:core" as core;
42+
43+
class ImportedClass extends core::Object {
44+
constructor •(core::String a) → self3::ImportedClass
45+
: super core::Object::•()
46+
;
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/issue34515.dart:9:3: Error: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
6+
// ImportedClass(1);
7+
// ^^^^^^^^^^^^^
8+
//
9+
// pkg/front_end/testcases/issue34515.dart:10:3: Error: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
10+
// ImportedClass("a");
11+
// ^^^^^^^^^^^^^
12+
//
13+
import self as self;
14+
import "dart:core" as core;
15+
16+
import "org-dartlang-testcase:///issue34515_lib1.dart";
17+
import "org-dartlang-testcase:///issue34515_lib2.dart";
18+
19+
static method test() → void {
20+
let final core::Object #t1 = 1 in invalid-expression "pkg/front_end/testcases/issue34515.dart:9:3: Error: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
21+
ImportedClass(1);
22+
^^^^^^^^^^^^^";
23+
let final core::Object #t2 = "a" in invalid-expression "pkg/front_end/testcases/issue34515.dart:10:3: Error: 'ImportedClass' is imported from both 'pkg/front_end/testcases/issue34515_lib1.dart' and 'pkg/front_end/testcases/issue34515_lib2.dart'.
24+
ImportedClass(\"a\");
25+
^^^^^^^^^^^^^";
26+
}
27+
static method main() → dynamic {}
28+
29+
library;
30+
import self as self2;
31+
import "dart:core" as core;
32+
33+
class ImportedClass extends core::Object {
34+
constructor •(core::int a) → self2::ImportedClass
35+
: super core::Object::•()
36+
;
37+
}
38+
39+
library;
40+
import self as self3;
41+
import "dart:core" as core;
42+
43+
class ImportedClass extends core::Object {
44+
constructor •(core::String a) → self3::ImportedClass
45+
: super core::Object::•()
46+
;
47+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
class ImportedClass {
6+
ImportedClass(int a);
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
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.
4+
5+
class ImportedClass {
6+
ImportedClass(String a);
7+
}

pkg/front_end/testcases/text_serialization.status

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ invalid_assignment: TextSerializationFailure # Was: Pass
665665
invalid_cast: TextSerializationFailure # Was: Pass
666666
invalid_type: TypeCheckError
667667
invocations: TextSerializationFailure # Was: RuntimeError
668+
issue34515: TextSerializationFailure
668669
issue34899: TypeCheckError
669670
literals: TextSerializationFailure # Was: Pass
670671
local_generic_function: TextSerializationFailure # Was: Pass

0 commit comments

Comments
 (0)