Skip to content

Add this as a self type#1708

Open
HT154 wants to merge 1 commit into
apple:mainfrom
HT154:this-type
Open

Add this as a self type#1708
HT154 wants to merge 1 commit into
apple:mainfrom
HT154:this-type

Conversation

@HT154

@HT154 HT154 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

This PR:

  • Adds type this, a fully featured self type for use in modules or classes.
    • Forbids use of this in typealias bodies.
  • Deprecates usage of the module type in class and typealias bodies with a warning, to be an error in a future release.
  • Adopts this in the standard library:
    • pkl.base#Any.getClass() now returns Class<this>.
    • pkl.ref#Domain.renderReference() now accepts a Reference<this, Any>.
  • This also a corner case with ReferenceTypeNode, module types, and type aliases that caused module types in the referent position to always be resolved to the module where the Reference type annotation is instead of where module is used.

Resolves #1612
Resolves #1712

sourceSection, clazz, PType.MODULE, MirrorFactories.moduleTypeFactory);
}

public static FinalSelfTypeNode thiz(SourceSection sourceSection, VmClass clazz) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any recs for a better name here? 😅

Comment on lines +190 to +194
/**
* If {@code frame} is provided then self types should be resolved to real types, otherwise return
* the self PType
*/
protected PType doExport(@Nullable VirtualFrame frame) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReferenceTypeNode needs to export the real class here, so when a frame is passed NonFinalSelfTypeNode uses it to get the target's class instead of exporting PType.MODULE/PType.THIS.

@HT154 HT154 force-pushed the this-type branch 2 times, most recently from 41b3a9f to 9d20551 Compare July 3, 2026 06:18
@HT154 HT154 marked this pull request as ready for review July 4, 2026 19:10
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.

module types as typelias type args are evaluated in the context of the alias's module, not where module is used Pkl is missing a self-type

1 participant