Skip to content

Disallow inferred splices and set the correct position #4780

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 1 commit into from
Jul 10, 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
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,7 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
quotation(quotedTree, tree)
case tree: TypeTree if tree.tpe.typeSymbol.isSplice =>
val splicedType = tree.tpe.stripTypeVar.asInstanceOf[TypeRef].prefix.termSymbol
if (levelOf.get(splicedType).contains(level)) tree
else splice(ref(splicedType).select(tpnme.UNARY_~))
splice(ref(splicedType).select(tpnme.UNARY_~).withPos(tree.pos))
case tree: Select if tree.symbol.isSplice =>
splice(tree)
case tree: RefTree if isCaptured(tree.symbol, level) =>
Expand Down
11 changes: 11 additions & 0 deletions tests/neg/i4774a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

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
Copy link
Member

Choose a reason for hiding this comment

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

Instead of giving an error, couldn't the typechecker be smart enough to dealias?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The difficulty is that this depends on the quotation level and we do not have it at typer time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't worry to much about this case and encourage the use of T instead of ~t.

'(y)
)
}
}
6 changes: 6 additions & 0 deletions tests/pos/i4774c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

import scala.quoted._

object Test {
def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] = '{ val y = ~x; ~loop('(y)) }
}
2 changes: 1 addition & 1 deletion tests/pos/i4774.scala → tests/pos/i4774d.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import scala.quoted._

object Test {
def loop[T](x: Expr[T])(implicit t: Type[T]): Expr[T] =
'{ val y: ~t = ~x; ~loop('(y)) }
'{ val y: T = ~x; ~loop('(y)) }
}