Skip to content

Add user generic methods - #1849

Draft
HT154 wants to merge 11 commits into
apple:mainfrom
HT154:method-call-type-args
Draft

HT154 wants to merge 11 commits into
apple:mainfrom
HT154:method-call-type-args

Conversation

@HT154

@HT154 HT154 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Changes:

  • Allow generic methods to be declared outside the standard library
  • Allow object (local) methods to be generic
  • Allow generic method call sites to specify type arguments explicitly
    • Unchanged: when no explicit type argument is provided, type parameter type checks are no-ops
  • Remove validation that ref.Reference type annotations may not contain constraints in the referent position. Any constraints are now silently dropped.
  • Change the ref.Reference() constructor signature:
import "pkl:ref"
before = ref.Reference(myDomain, MyReferent, myData)
after = ref.Reference::<MyDomain, MyReferent>(myDomain, myData)

// this can be cleaned up behind a generic typealias and method:
typealias MyRef<T> = ref.Reference<MyDomain, T>
function MyRef<T>(data: Any): MyRef<T> = ref.Reference::<MyDomain, T>(myDomain, data)
after2 = MyRef::<MyReferent>(myData)

// and references can now be constructed directly to complex types
complex1 = MyRef::<Listing<String>>(null)
complex2 = MyRef::<String | Int>(null)
complex3 = MyRef::<this>(null)
complex4 = MyRef::<(String) -> Int>(null)

Depends on #1838

@HT154
HT154 force-pushed the method-call-type-args branch 3 times, most recently from c29cca5 to 64997b5 Compare September 9, 2026 21:25
@HT154 HT154 changed the title Allow generic method callers to specify explicit type arguments Add user generic methods Sep 9, 2026
@HT154
HT154 force-pushed the method-call-type-args branch 4 times, most recently from 477d8e5 to 157a9b4 Compare September 15, 2026 19:54
@HT154
HT154 force-pushed the method-call-type-args branch 4 times, most recently from 672a667 to aa82316 Compare September 17, 2026 16:15
@HT154
HT154 force-pushed the method-call-type-args branch from aa82316 to 280fd60 Compare September 17, 2026 20:14
@HT154
HT154 force-pushed the method-call-type-args branch from 9c7b7f1 to d26c92f Compare September 18, 2026 15:46
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.

1 participant