Skip to content

Commit c7bce42

Browse files
jensjohaCommit Queue
authored andcommitted
[CFE] Fix expression compilation with extension methods imported via prefix
Fixes #56554 Change-Id: I060a76cc3d3bb946283eff17c8feb93f136a8d8f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389100 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent 54f1ee4 commit c7bce42

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

pkg/front_end/lib/src/base/incremental_compiler.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,8 +2049,26 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
20492049
indexedLibrary: null,
20502050
mayImplementRestrictedTypes: false);
20512051

2052+
SourceLibraryBuilder? orgDebugLibrary = debugLibrary;
20522053
debugLibrary = debugCompilationUnit.createLibrary();
20532054

2055+
// Copy over the prefix namespace for extensions
2056+
// (`forEachExtensionInScope`) to be found when imported via prefixes.
2057+
// TODO(johnniwinther): Extensions should be available through
2058+
// [parentScope].
2059+
orgDebugLibrary.prefixNameSpace.forEachLocalMember((name, member) {
2060+
debugLibrary.prefixNameSpace
2061+
.addLocalMember(name, member, setter: false);
2062+
});
2063+
// Does a prefix namespace ever have anything but locals?
2064+
orgDebugLibrary.prefixNameSpace.forEachLocalSetter((name, member) {
2065+
debugLibrary.prefixNameSpace.addLocalMember(name, member, setter: true);
2066+
});
2067+
orgDebugLibrary.prefixNameSpace.forEachLocalExtension((member) {
2068+
debugLibrary.prefixNameSpace.addExtension(member);
2069+
});
2070+
orgDebugLibrary = null;
2071+
20542072
HybridFileSystem hfs =
20552073
lastGoodKernelTarget.fileSystem as HybridFileSystem;
20562074
MemoryFileSystem fs = hfs.memory;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (c) 2024, 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+
entry_point: a1.dart
6+
sources:
7+
a1.dart: |
8+
import 'a2.dart' as ext;
9+
import 'a3.dart';
10+
11+
void stopHere() {
12+
final i = 0;
13+
print(i.f1());
14+
print(i.f2());
15+
print(i.f3());
16+
}
17+
18+
extension E1 on int {
19+
int f1() => this;
20+
}
21+
a2.dart: |
22+
extension E2 on int {
23+
int f2() => this;
24+
}
25+
a3.dart: |
26+
extension E3 on int {
27+
int f3() => this;
28+
}
29+
definitions: ["i"]
30+
# int
31+
definition_types: ["dart:core", "int", "1", "0"]
32+
type_definitions: []
33+
type_bounds: []
34+
type_defaults: []
35+
method: "stopHere"
36+
expression: |
37+
i.f1() + i.f2() + i.f3()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Errors: {
2+
}
3+
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr(dart.core::int i) → dynamic
4+
return #lib1::E1|f1(i).{dart.core::num::+}(#lib2::E2|f2(i)){(dart.core::num) → dart.core::int}.{dart.core::num::+}(#lib3::E3|f3(i)){(dart.core::num) → dart.core::int};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (c) 2024, 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+
entry_point: a1.dart
6+
sources:
7+
a1.dart: |
8+
import 'a2.dart' as ext;
9+
10+
void stopHere() {
11+
ext.foo();
12+
}
13+
a2.dart: |
14+
void foo() {}
15+
definitions: []
16+
definition_types: []
17+
type_definitions: []
18+
type_bounds: []
19+
type_defaults: []
20+
method: "stopHere"
21+
expression: |
22+
ext.foo()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Errors: {
2+
}
3+
method /* from org-dartlang-debug:synthetic_debug_expression */ debugExpr() → dynamic
4+
return #lib1::foo();

0 commit comments

Comments
 (0)