-
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
Fix opaque types leaking rhs when inlined and found in type params (and a related stale symbol issue) #22655
Open
jchyb
wants to merge
3
commits into
scala:main
Choose a base branch
from
dotty-staging:fix-i20449-stale-opaque
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.
+147
−2
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import scala.quoted.* | ||
transparent inline def getTypeInfo[T]() = ${ getTypeInfoImpl[T] } | ||
def getTypeInfoImpl[T: Type](using ctx: Quotes): Expr[Unit] = '{ () } |
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 @@ | ||
|
||
class Wrapper1[A] | ||
val a = { | ||
getTypeInfo[Any]() | ||
val wrapper2 = Wrapper1[Any]() | ||
} |
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,50 @@ | ||
------ UserName.T - Directly ------- | ||
Original: Main_2$package.UserName.T | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ UserName.T - Directly ------- | ||
Original: Main_2$package.UserName | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ ForeignWrapper1[UserName.T] ------- | ||
Original: Main_2$package.UserName.T | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ ForeignWrapper2[UserName.T] ------- | ||
Original: Main_2$package.UserName.T | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ ForeignWrapper1[UserName] ------- | ||
Original: Main_2$package.UserName | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ ForeignWrapper2[UserName] ------- | ||
Original: Main_2$package.UserName | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ Wrapper1[UserName.T] ------- | ||
Original: Main_2$package.UserName.T | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ Wrapper2[UserName.T] ------- | ||
Original: Main_2$package.UserName.T | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ Wrapper1[UserName] ------- | ||
Original: Main_2$package.UserName | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
||
------ Wrapper2[UserName] ------- | ||
Original: Main_2$package.UserName | ||
Dealias: Main_2$package.UserName.T | ||
Dealias dealias: Main_2$package.UserName.T | ||
|
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,29 @@ | ||
import scala.quoted.* | ||
|
||
class ForeignWrapper1[-A] { | ||
inline def getTypeInfo(inline source: String): String = | ||
${ getTypeInfoImpl[A]('source) } | ||
def createWrapper2 = ForeignWrapper2(this) | ||
} | ||
|
||
class ForeignWrapper2[-A](val self: ForeignWrapper1[A]) { | ||
inline def getTypeInfo(inline source: String): String = | ||
${getTypeInfoImpl[A]('source)} | ||
} | ||
|
||
transparent inline def getTypeInfo[T](inline source: String) = | ||
${ getTypeInfoImpl[T]('source) } | ||
|
||
def getTypeInfoImpl[T: Type](source: Expr[String])(using ctx: Quotes) : Expr[String] = { | ||
import ctx.reflect.* | ||
|
||
val tpe = TypeRepr.of[T] | ||
val str = | ||
s"""|------ ${source.valueOrAbort} ------- | ||
|Original: ${tpe.show} | ||
|Dealias: ${tpe.dealias.show} | ||
|Dealias dealias: ${tpe.dealias.dealias.show} | ||
""".stripMargin | ||
|
||
Expr(str) | ||
} |
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,41 @@ | ||
object UserName { | ||
opaque type T = String | ||
|
||
def apply(s: String): T = s | ||
} | ||
|
||
type UserName = UserName.T | ||
|
||
class Wrapper1[-A] { | ||
inline def getTypeInfo(inline source: String): String = | ||
${ getTypeInfoImpl[A]('source) } | ||
def createWrapper2 = Wrapper2(this) | ||
} | ||
|
||
class Wrapper2[-A](val self: Wrapper1[A]) { | ||
inline def getTypeInfo(inline source: String): String = | ||
${getTypeInfoImpl[A]('source)} | ||
} | ||
|
||
|
||
@main def Test() = { | ||
println(getTypeInfo[UserName.T]("UserName.T - Directly")) | ||
println(getTypeInfo[UserName]("UserName.T - Directly")) | ||
|
||
val foreignWrapper = ForeignWrapper1[UserName.T]() | ||
println(foreignWrapper.getTypeInfo("ForeignWrapper1[UserName.T]")) | ||
println(foreignWrapper.createWrapper2.getTypeInfo("ForeignWrapper2[UserName.T]")) | ||
|
||
val foreignWrapper2 = ForeignWrapper1[UserName]() | ||
println(foreignWrapper2.getTypeInfo("ForeignWrapper1[UserName]")) | ||
println(foreignWrapper2.createWrapper2.getTypeInfo("ForeignWrapper2[UserName]")) | ||
|
||
val wrapper = Wrapper1[UserName.T]() | ||
println(wrapper.getTypeInfo("Wrapper1[UserName.T]")) | ||
println(wrapper.createWrapper2.getTypeInfo("Wrapper2[UserName.T]")) | ||
|
||
val wrapper2 = Wrapper1[UserName]() | ||
println(wrapper2.getTypeInfo("Wrapper1[UserName]")) | ||
println(wrapper2.createWrapper2.getTypeInfo("Wrapper2[UserName]")) | ||
|
||
} |
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.
Can you add a little detail in a comment about this usage (with any references that would be helpful)