-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add constructors for TypeOrBounds that are not refs or PolyType #7961
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
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Ok |
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,57 @@ | ||
import tasty._ | ||
import quoted._ | ||
|
||
object Macros { | ||
inline def theTestBlock : Unit = ${ theTestBlockImpl } | ||
|
||
trait RefineMe { | ||
type T | ||
def foo : T | ||
} | ||
|
||
class TestAnnotation extends scala.annotation.Annotation | ||
|
||
def theTestBlockImpl(given qctx : QuoteContext) : Expr[Unit] = { | ||
import qctx.tasty.{_,given} | ||
|
||
val x1T = ConstantType(Constant(1)) | ||
val x2T = OrType(ConstantType(Constant(1)), ConstantType(Constant(2))) | ||
val x3T = AndType(ConstantType(Constant(3)), typeOf[Any]) | ||
val x4T = | ||
TypeLambda( | ||
List("A","B"), | ||
_ => List(TypeBounds(typeOf[Nothing], typeOf[Any]), TypeBounds(typeOf[Nothing], typeOf[Any])), | ||
(tl : TypeLambda) => tl.param(1)) | ||
val x5T = | ||
Refinement( | ||
typeOf[RefineMe], | ||
"T", | ||
TypeBounds(typeOf[Int], typeOf[Int])) | ||
val x6T = AppliedType(Type(classOf[List[_]]), List(typeOf[Int])) | ||
val x7T = AnnotatedType(ConstantType(Constant(7)), '{ new TestAnnotation }.unseal) | ||
val x8T = | ||
MatchType( | ||
typeOf[Int], | ||
typeOf[List[8]], | ||
List( | ||
TypeLambda( | ||
List("t"), | ||
_ => List(TypeBounds(typeOf[Nothing], typeOf[Any])), | ||
tl => AppliedType(MatchCaseType, List(AppliedType(Type(classOf[List[_]]), List(tl.param(0))), tl.param(0))))) | ||
) | ||
|
||
assert(x1T =:= '[1].unseal.tpe) | ||
assert(x2T =:= '[1|2].unseal.tpe) | ||
assert(x3T =:= '[3&Any].unseal.tpe) | ||
assert(x4T =:= '[[A,B] =>> B].unseal.tpe) | ||
assert(x5T =:= '[RefineMe { type T = Int }].unseal.tpe) | ||
assert(x6T =:= '[List[Int]].unseal.tpe) | ||
assert(x7T =:= '[7 @TestAnnotation].unseal.tpe) | ||
assert(x8T =:= '[List[8] match { case List[t] => t }].unseal.tpe) | ||
|
||
'{ | ||
println("Ok") | ||
} | ||
} | ||
} | ||
|
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 @@ | ||
|
||
object Test { | ||
def main(args : Array[String]) : Unit = | ||
Macros.theTestBlock | ||
} | ||
|
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.
This is too hacky. In the future, we won't have access to the
classOf[MatchCase[_, _]]
. This should probably be in thescala.internal
interface (CompilerInterface
).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.
This is interesting. Even in the tests, I had to use
Type(classOf[List[_]])
in order to get the type ofList
.Actually writing
typeOf[List]
gives memissing type parameter(s) for List
. WritingtypeOf[List[_]]
satisfies Dotty but gives meAppliedType(List, TypeBounds(Nothing,Any))
, which is not helpful.Is this a bug or am I doing it wrong?
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.
(leaving is as-is for now since it makes more sense to change this and the tests at the same time once we figure out the above question)