Skip to content

Fix #4891: Make scala.quoted.Expr covariant #4894

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 2 commits into from
Aug 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/src/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scala.quoted

import scala.runtime.quoted.Unpickler.Pickled

sealed abstract class Expr[T] {
sealed abstract class Expr[+T] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd make sense to make the subclasses covariant too for consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will add apt them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in #4896

final def unary_~ : T = throw new Error("~ should have been compiled away")

/** Evaluate the contents of this expression and return the result.
Expand Down
4 changes: 1 addition & 3 deletions tests/neg/i4774a.scala → tests/pos/i4774a.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import scala.quoted._
object Test {
def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = '{
val y: ~t = ~x
~loop( // error: inferred loop[~t] where T should be used
'(y)
)
~loop('(y))
}
}
5 changes: 5 additions & 0 deletions tests/pos/i4891.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import scala.quoted._

object Test {
def foo: Expr[Option[String]] = '(None)
}