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

call to nullary, polymorphic macro without explicit type argument lead to NoSuchMethodError #5692

Closed
scabug opened this Issue Apr 22, 2012 · 9 comments

Comments

Projects
None yet
2 participants
@scabug
Copy link

scabug commented Apr 22, 2012

~/code/scala ./build/quick/bin/scala
Welcome to Scala version 2.10.0-20120422-061223-8c95273b70 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).

scala> def impl[A](c: reflect.makro.Context) = c.reify(())
impl: [A](c: scala.reflect.makro.Context)c.mirror.Expr[Unit]

scala> def decl[A] = macro impl[A]
decl: [A]=> Unit

scala> decl[Any]

scala> decl
java.lang.NoSuchMethodError: .decl()V
	at .<init>(<console>:12)
	at .<clinit>(<console>)
	at .<init>(<console>:7)
	at .<clinit>(<console>)
	at $print(<console>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:776)
	at scala.tools.nsc.interpreter.IMain$Request$$anonfun$16.apply(IMain.scala:1040)
	at scala.tools.nsc.interpreter.Line.scala$tools$nsc$interpreter$Line$$runAndSetState(Line.scala:41)
	at scala.tools.nsc.interpreter.Line$$anonfun$2.apply$mcV$sp(Line.scala:47)
	at scala.tools.nsc.io.package$$anon$2.run(package.scala:22)
	at java.lang.Thread.run(Thread.java:680)
@scabug

This comment has been minimized.

Copy link

scabug commented Apr 22, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5692?orig=1
Reporter: @retronym
Affected Versions: 2.10.0-M7, 2.10.0

@scabug

This comment has been minimized.

Copy link

scabug commented Apr 25, 2012

@xeno-by said:
There's another flavor of this bug, one that manifests when you write "val x = decl". Since macroExpand is mutually exclusive with instantiate, decl never gets a chance to instantiate. Instead it tries to expand, gets delayed because of undetParams, and ends up both polymorphic and not expanded.

@scabug

This comment has been minimized.

Copy link

scabug commented May 5, 2012

@retronym said:
This now reports:

scala> decl
<console>:11: error: macro has not been expanded
              decl
              ^
@scabug

This comment has been minimized.

Copy link

scabug commented May 5, 2012

@xeno-by said:
That's expected.

The original bug was caused by the fact that polymorphic expansions with undetermined params are delayed until params get inferred. This works in a lot of cases, except of this one that I overlooked.

Interaction of undetParams and macros will be revised anyways, when I get to implicit macros (hopefully, before M4), so for now I added a "macro has not been expanded" sanity check akin to "erroneous or inaccessible type". Of course, this change doesn't prevent a bug, but at least it makes the bug apparent during compile-time, not during the runtime.

@scabug

This comment has been minimized.

Copy link

scabug commented Jun 9, 2012

@xeno-by said (edited on Sep 17, 2012 10:30:43 PM UTC):
Fixed in scala/scala@ce67870
Update. Actually I have no idea how exactly the linked commit fixes this issue. Probably I closed the wrong bug.

@scabug

This comment has been minimized.

Copy link

scabug commented Sep 2, 2012

@Blaisorblade said (edited on Sep 2, 2012 3:20:38 PM UTC):
Currently we still get the "macro has not been expanded" error, which is too cryptic and should be fixed. A correct error message should be "type parameter not specified". Given Eugene's comment, the plan was to change this error, but we're nearing release and that did not happen yet. So I'm reopening this bug.

Below an updated REPL session (with a number of small changes due to updates to the macro API).

scala> import language.experimental.macros
import language.experimental.macros

cala> def impl[A](c: reflect.macros.Context) = c.universe.reify(())
impl: [A](c: scala.reflect.macros.Context)c.universe.Expr[Unit]

scala> def decl[A] = macro impl[A]
decl: [A]=> Unit

scala> decl[Any]

scala> decl
<console>:11: error: macro has not been expanded
              decl
              ^
@scabug

This comment has been minimized.

Copy link

scabug commented Sep 2, 2012

@xeno-by said:
Thanks I'll look into it

@scabug

This comment has been minimized.

Copy link

scabug commented Sep 17, 2012

@xeno-by said:
Error message now looks better: scala/scala#1329. However the underlying issue is still too fundamental to be fixed before 2.10.0-final. Therefore demoting back to major.

@scabug

This comment has been minimized.

Copy link

scabug commented Jan 15, 2013

@xeno-by said:
Fixed in scala/scala@fe60284

@scabug scabug closed this Jan 15, 2013

@scabug scabug added this to the 2.11.0-M2 milestone Apr 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment