-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Implement applied constructor types #22543
Open
KacperFKorban
wants to merge
15
commits into
scala:main
Choose a base branch
from
dotty-staging:mb/applied-constructors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+184
−37
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
09aa88d
Add support for applied constructor sugar
mbovel 50a8347
Move applied constructor types under modularity
KacperFKorban 4ef6ac2
Support nested constructor applications as types
KacperFKorban ad9d163
Extract applied constructors logic to a separate function
KacperFKorban 26908e2
Fix desugaring explicitly applied generics
KacperFKorban 4848e07
Some more applied constructor tests
KacperFKorban ab7d45a
Parse applied constructor type arguments as trees
mbovel 2b884f5
Update check file for applied constructor types neg test
KacperFKorban 21888c6
Extract a tracked related bug to a separate issue: #22540
KacperFKorban a119e08
Add a warning message for a pointless applied constructor type use
KacperFKorban e68753a
Add docs and syntax change for applied constructor types
KacperFKorban 69ff014
Prevent crashes in erroneous cases
KacperFKorban a23b628
More applied constructor types fixes
KacperFKorban 64aee9d
Ignore best effort compilation failure; add some more controversial
KacperFKorban 838a3bc
Warn when a non-fully-dependent class is used with applied constructo…
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 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 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 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 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 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 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 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 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 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 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 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 | ||
|
||
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 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 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 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 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 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 @@ | ||
-- [E209] 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 that only have tracked parameters |
This file contains 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 |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about constructors with mixed tracked and non-tracked parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some tests for those, but the current approach is: you have to write all parameters, but the non-tracked params won't influence the resulting type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that sounds strange, so a bit like an unused function parameter? maybe there should be a placeholder like
erasedValue
or?
for now?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't have to be unused, though one might argue that it makes it worse 😅 BUT, the following works: