Skip to content

Fix #7839: Improve error message for implicit parameters #8960

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
May 13, 2020
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
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ object Splicer {
// OK

case _ =>
val extra = if tree.span.isZeroExtent then ": " + tree.show else ""
ctx.error(
"""Malformed macro parameter
s"""Malformed macro parameter$extra
|
|Parameters may be:
|Parameters may only be:
| * Quoted parameters or fields
| * References to inline parameters
| * Literal values of primitive types
|""".stripMargin, tree.sourcePos)
}
Expand Down
8 changes: 8 additions & 0 deletions tests/neg-macros/i7839.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Error: tests/neg-macros/i7839.scala:4:18 ----------------------------------------------------------------------------
4 | ${ transformImpl } // error
| ^
| Malformed macro parameter: dummyImplicit
|
| Parameters may only be:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does it resolve DummyImplicit at all if it is neither of the two cases below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a static check that happens after typechecking. We do not modify in any way the typing of expressions within top level splices, we only restrict it based terms that can be interpreted when evaluating the macro.

| * Quoted parameters or fields
| * Literal values of primitive types
6 changes: 6 additions & 0 deletions tests/neg-macros/i7839.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import scala.quoted._

inline def transform(using dummyImplicit: DummyImplicit): Unit =
${ transformImpl } // error

def transformImpl(using dummyImplicit: DummyImplicit)(using QuoteContext): Expr[Unit] = ???