Skip to content

Fix abstract class with default constructor crashes compiler#284

Open
khoadng wants to merge 1 commit into
ethanblake4:masterfrom
khoadng:fix/abstract-class-polymorphism
Open

Fix abstract class with default constructor crashes compiler#284
khoadng wants to merge 1 commit into
ethanblake4:masterfrom
khoadng:fix/abstract-class-polymorphism

Conversation

@khoadng
Copy link
Copy Markdown
Contributor

@khoadng khoadng commented Mar 21, 2026

Extending an abstract class that has no explicit constructor crashed with a null check error in OffsetTracker

Comment thread lib/src/eval/compiler/reference.dart Outdated
Root cause: IdentifierReference.name arrives as 'ClassName.' (trailing
dot) when resolving default super constructors — constructor.dart builds
'${extendsType.name}.$constructorName' where constructorName is empty.
Then _declarationToVariable/_declarationToStaticDispatch appends another
dot via '$name.', producing 'ClassName..' which doesn't match the
registered key 'ClassName.' in topLevelDeclarationPositions.

Fix: extract _resolveDefaultConstructorOffset that normalizes name to
bare class name before building the constructor key, so the key is
always consistently 'ClassName.'.
@khoadng khoadng force-pushed the fix/abstract-class-polymorphism branch from baee0e4 to 7d54a93 Compare March 24, 2026 02:57
@khoadng
Copy link
Copy Markdown
Contributor Author

khoadng commented Mar 24, 2026

Pushed a new approach.

I think the root cause is that member keys are raw strings with an implicit dot convention. Code that builds '$name.$ctorName' with empty ctorName produces 'C.', which then flows through paths that append . again. A structured key type would eliminate this class of bugs entirely, but that touches a lot of files and probably too big for this PR.

@Zverik
Copy link
Copy Markdown
Collaborator

Zverik commented Mar 24, 2026

This looks same but better. Thanks! I've approved it, but will need to wait for Ethan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants