-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement applied constructor types #22543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
KacperFKorban
merged 16 commits into
scala:main
from
dotty-staging:mb/applied-constructors
May 1, 2025
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b6b12f3
Add support for applied constructor sugar
mbovel 67191b3
Move applied constructor types under modularity
KacperFKorban 896c844
Support nested constructor applications as types
KacperFKorban a0833b3
Extract applied constructors logic to a separate function
KacperFKorban 0616734
Fix desugaring explicitly applied generics
KacperFKorban ca070a0
Some more applied constructor tests
KacperFKorban 2b71bfd
Parse applied constructor type arguments as trees
mbovel 1f91fe6
Update check file for applied constructor types neg test
KacperFKorban f7f49f9
Extract a tracked related bug to a separate issue: #22540
KacperFKorban d9fe503
Add a warning message for a pointless applied constructor type use
KacperFKorban 77b0eef
Add docs and syntax change for applied constructor types
KacperFKorban 32906fc
Prevent crashes in erroneous cases
KacperFKorban 05882db
More applied constructor types fixes
KacperFKorban 36648f7
Ignore best effort compilation failure; add some more controversial
KacperFKorban 04642f5
Warn when a non-fully-dependent class is used with applied constructo…
KacperFKorban d3fe2d5
Review changes for applied constructor types
KacperFKorban File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- [E006] Not Found Error: tests/neg/applied_constructor_types.scala:8:10 ---------------------------------------------- | ||
8 | val v1: f(1) = f(1) // error | ||
| ^ | ||
| Not found: type f | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E006] Not Found Error: tests/neg/applied_constructor_types.scala:9:10 ---------------------------------------------- | ||
9 | val v2: id(1) = f(1) // error | ||
| ^^ | ||
| Not found: type id - did you mean is? | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E006] Not Found Error: tests/neg/applied_constructor_types.scala:10:10 --------------------------------------------- | ||
10 | val v3: idDependent(1) = f(1) // error | ||
| ^^^^^^^^^^^ | ||
| Not found: type idDependent | ||
| | ||
| longer explanation available when compiling with `-explain` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import scala.language.experimental.modularity | ||
|
||
def f(x: Int): Int = x | ||
def id[T](x: T): T = x | ||
def idDependent(x: Any): x.type = x | ||
|
||
KacperFKorban marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def test = | ||
val v1: f(1) = f(1) // error | ||
val v2: id(1) = f(1) // error | ||
val v3: idDependent(1) = f(1) // error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import language.`3.3` | ||
val a = Some(a=a,)=> // error // error // error // error | ||
val a = Some(a=a,)=> // error // error // error | ||
val a = Some(x=y,)=> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import scala.language.experimental.modularity | ||
|
||
class Box(tracked val v: Any) | ||
class C(tracked val x: Int) | ||
class NC(tracked val c: C) | ||
class NNC(tracked val c: NC) | ||
class F[A](tracked val a: Int) | ||
class G[A](tracked val a: A) | ||
class NF[A](tracked val f: F[A]) | ||
|
||
class Person(val name: String, tracked val age: Int) | ||
class PersonPrime(val name: String)(tracked val age: Int) | ||
class PersonBis(tracked val name: String)(val age: Int) | ||
|
||
class Generic[A](val a: A) | ||
|
||
object O: | ||
val m: Int = 27 | ||
|
||
class InnerClass(tracked val x: Int) | ||
|
||
object Test extends App { | ||
val c: C(42) = C(42) | ||
val nc: NC(C(42)) = NC(C(42)) | ||
val nc1: NC(c) = NC(c) | ||
val nnc: NNC(NC(C(42))) = NNC(NC(C(42))) | ||
val f: F[Int](42) = F[Int](42) | ||
val f2: F[Int](42) = F(42) | ||
val f3: F(42) = F(42) | ||
val g: G(42) = G(42) | ||
|
||
val n: Int = 27 | ||
val c2: C(n) = C(n) | ||
val c3: C(O.m) = C(O.m) | ||
|
||
val box: Box(O.InnerClass(42)) = Box(O.InnerClass(42)) | ||
val box2: Box(O.InnerClass(n)) = Box(O.InnerClass(n)) | ||
val box3: Box(O.InnerClass(O.m)) = Box(O.InnerClass(O.m)) | ||
|
||
val person: Person("Kasia", 27) = Person("Kasia", 27) // warn | ||
val person1: Person("Kasia", n) = Person("Kasia", n) // warn | ||
val person2: Person("Kasia", O.m) = Person("Kasia", O.m) // warn | ||
|
||
val personPrime: PersonPrime("Kasia")(27) = PersonPrime("Kasia")(27) // warn | ||
val personPrime1: PersonPrime("Kasia")(n) = PersonPrime("Kasia")(n) // warn | ||
val personPrime2: PersonPrime("Kasia")(O.m) = PersonPrime("Kasia")(O.m) // warn | ||
|
||
val personBis: PersonBis("Kasia")(27) = PersonBis("Kasia")(27) // warn | ||
val personBis1: PersonBis("Kasia")(n) = PersonBis("Kasia")(n) // warn | ||
val personBis2: PersonBis("Kasia")(O.m) = PersonBis("Kasia")(O.m) // warn | ||
|
||
val generic1: Generic(compiletime.erasedValue[Int]) = Generic(42) // warn | ||
val generic2: Generic(??? : Int) = Generic(42) // warn | ||
val generic3: Generic(43) = Generic(42) // warn | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- [E212] Type Warning: tests/warn/applied_constructor_types.scala:6:10 ------------------------------------------------ | ||
6 | val v1: UnspecificBox(4) = UnspecificBox(4) // warn | ||
| ^^^^^^^^^^^^^^^^ | ||
|Applied constructor type can only be used with classes where all parameters in the first parameter list are tracked |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import scala.language.experimental.modularity | ||
|
||
class UnspecificBox(val v: Any) | ||
|
||
def test = | ||
val v1: UnspecificBox(4) = UnspecificBox(4) // warn |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.