Skip to content

Commit c8f16b0

Browse files
jensjohaCommit Queue
authored andcommitted
[CFE] Fix crash in finalize export for extension types
The used reference wasn't registered where we look it up when finalizing exports which caused a crash. Fixes #60236 Change-Id: Id8807d1a53fa433806061a08b904d2cc2ef3e2fb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432640 Commit-Queue: Jens Johansen <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 58f2d59 commit c8f16b0

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

pkg/front_end/lib/src/source/type_parameter_scope_builder.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,6 +2428,10 @@ _AddBuilder _createExtensionTypeBuilder(ExtensionTypeFragment fragment,
24282428
fragment: fragment,
24292429
indexedContainer: indexedContainer,
24302430
representationFieldFragment: representationFieldFragment);
2431+
if (indexedContainer?.reference != null) {
2432+
loader.buildersCreatedWithReferences[indexedContainer!.reference] =
2433+
extensionTypeDeclarationBuilder;
2434+
}
24312435
return new _AddBuilder(
24322436
fragment.name, extensionTypeDeclarationBuilder, fragment.uriOffset,
24332437
inPatch: fragment.enclosingCompilationUnit.isPatch);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2025, 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+
# Reproduce a crash in ExtensionTypeDeclaration.enclosingLibrary
6+
# when finalizing exports.
7+
# Likely also whats seen in https://github.com/dart-lang/sdk/issues/60236.
8+
9+
type: newworld
10+
worlds:
11+
- entry:
12+
- bar.dart
13+
sources:
14+
foo.dart: |
15+
export 'bar.dart';
16+
bar.dart: |
17+
import 'foo.dart';
18+
extension type Baz(String qux) {}
19+
expectedLibraryCount: 2
20+
21+
- entry:
22+
- bar.dart
23+
worldType: updated
24+
expectInitializeFromDill: false
25+
invalidate:
26+
- bar.dart
27+
expectedLibraryCount: 2
28+
advancedInvalidation: bodiesOnly # or something else?
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
main = <No Member>;
2+
library from "org-dartlang-test:///bar.dart" as bar {
3+
4+
import "org-dartlang-test:///foo.dart";
5+
6+
extension type Baz(dart.core::String qux) {
7+
abstract extension-type-member representation-field get qux() → dart.core::String;
8+
constructor • = bar::Baz|constructor#;
9+
constructor tearoff • = bar::Baz|constructor#_#new#tearOff;
10+
}
11+
static extension-type-member method Baz|constructor#(dart.core::String qux) → bar::Baz% /* erasure=dart.core::String, declared=! */ {
12+
lowered final bar::Baz% /* erasure=dart.core::String, declared=! */ #this = qux;
13+
return #this;
14+
}
15+
static extension-type-member synthetic method Baz|constructor#_#new#tearOff(dart.core::String qux) → bar::Baz% /* erasure=dart.core::String, declared=! */
16+
return bar::Baz|constructor#(qux);
17+
}
18+
library from "org-dartlang-test:///foo.dart" as foo {
19+
additionalExports = (bar::Baz)
20+
21+
export "org-dartlang-test:///bar.dart";
22+
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
main = <No Member>;
2+
library from "org-dartlang-test:///bar.dart" as bar {
3+
4+
import "org-dartlang-test:///foo.dart";
5+
6+
extension type Baz(dart.core::String qux) {
7+
abstract extension-type-member representation-field get qux() → dart.core::String;
8+
constructor • = bar::Baz|constructor#;
9+
constructor tearoff • = bar::Baz|constructor#_#new#tearOff;
10+
}
11+
static extension-type-member method Baz|constructor#(dart.core::String qux) → bar::Baz% /* erasure=dart.core::String, declared=! */ {
12+
lowered final bar::Baz% /* erasure=dart.core::String, declared=! */ #this = qux;
13+
return #this;
14+
}
15+
static extension-type-member synthetic method Baz|constructor#_#new#tearOff(dart.core::String qux) → bar::Baz% /* erasure=dart.core::String, declared=! */
16+
return bar::Baz|constructor#(qux);
17+
}
18+
library from "org-dartlang-test:///foo.dart" as foo {
19+
additionalExports = (bar::Baz)
20+
21+
export "org-dartlang-test:///bar.dart";
22+
23+
}

0 commit comments

Comments
 (0)