Skip to content

Fix #6783: Check all owner to detect if inside an inline method #6788

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 2, 2019
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 compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2082,7 +2082,7 @@ class Typer extends Namer
}

private def checkSpliceOutsideQuote(tree: untpd.Tree)(implicit ctx: Context): Unit = {
if (level == 0 && !ctx.owner.isInlineMethod)
if (level == 0 && !ctx.owner.ownersIterator.exists(_.is(Inline)))
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the following code?

inline def foo() = {
  class A {
    def bar = $(...)
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will fall back to error message of the macro body checking .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those checks are performed by the Splicer

ctx.error("Splice ${...} outside quotes '{...} or inline method", tree.sourcePos)
else if (level < 0)
ctx.error(
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/i6783.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted._

inline def test(f: (Int, Int) => Int) = ${ // error: Malformed macro
testImpl((a: Expr[Int], b: Expr[Int]) => '{ f(${a}, ${b}) })
}

def testImpl(f: (Expr[Int], Expr[Int]) => Expr[Int]): Expr[Int] = ???
7 changes: 7 additions & 0 deletions tests/pos/i6783.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted._

def testImpl(f: Expr[(Int, Int) => Int]): Expr[Int] = f('{1}, '{2})

inline def test(f: (Int, Int) => Int) = ${
testImpl('f)
}