Skip to content
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

Implicit macros are broken #5923

Closed
scabug opened this issue Jun 15, 2012 · 15 comments
Closed

Implicit macros are broken #5923

scabug opened this issue Jun 15, 2012 · 15 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jun 15, 2012

Currently implicit defs, which are also macros, are expanded too early (typed1 in typedImplicit1), which means that they cannot be used to generate type tags.

scala> def impl[T: c.WeakTypeTag](c: Context) = { println(c.weakTypeOf[T]); c.Expr[C[T]](c.universe.Literal(c.universe.Constant(null))) }
impl: [T](c: scala.reflect.macros.Context)(implicit evidence$1: c.WeakTypeTag[T])c.Expr[C[T]]

scala> class C[T]defined class C

scala> def impl[T: c.WeakTypeTag](c: Context) = { println(c.weakTypeOf[T]); c.Expr[C[T]](c.universe.Literal(c.universe.Constant(null))) }
impl: [T](c: scala.reflect.macros.Context)(implicit evidence$1: c.WeakTypeTag[T])c.Expr[C[T]]

scala> implicit def foo[T]: C[T] = macro impl[T]
foo: [T]=> C[T]

scala> implicitly[C[Int]]
<console>:30: foo is not a valid implicit value for C[Int] because:
incompatible: C[T] does not match expected type C[Int]
              implicitly[C[Int]]
                        ^
<console>:30: error: could not find implicit value for parameter e: C[Int]
              implicitly[C[Int]]
                        ^
@scabug
Copy link
Author

scabug commented Jun 15, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5923?orig=1
Reporter: @xeno-by
Affected Versions: 2.10.0

@scabug
Copy link
Author

scabug commented Jun 28, 2012

@xeno-by said:
Also see #5743

@scabug
Copy link
Author

scabug commented Dec 2, 2012

@xeno-by said:
Of interest is this stackoverflow question: http://stackoverflow.com/questions/13669974/static-return-type-of-scala-macros

@scabug
Copy link
Author

scabug commented Dec 9, 2012

@xeno-by said:
Also see #5692

@scabug
Copy link
Author

scabug commented Jan 7, 2013

@xeno-by said:
Partially fixed in scala/scala#1844

Future work:

@scabug
Copy link
Author

scabug commented Jan 20, 2013

@xeno-by said:
The adapt fix has now been in trunk for quite long. The only thing that stops me from closing this issue is pending migration of type tags.

@scabug
Copy link
Author

scabug commented Jan 26, 2013

@xeno-by said:
Unfortunately that fix caused a regression: https://groups.google.com/forum/#!topic/scala-internals/7pA9CiiD3u8. Nevertheless, I think it's too valuable, so I'll try to see what can be done here to fix the regression and backport the fix to 2.10.1.

@scabug
Copy link
Author

scabug commented Feb 4, 2013

@retronym said:
demoting to 2.10.2, the fix in master caused a regression and must be reworked a little

@scabug
Copy link
Author

scabug commented Mar 28, 2013

Leonard Schneider (leonard.schneider) said:
I'm currently blocked by this issue. Is it possible to have a 2.10.2 nightly build with a fix?

@scabug
Copy link
Author

scabug commented Mar 29, 2013

@xeno-by said:
Currently I'm travelling, so I'll be able to take a good look at it probably not earlier than after the weekend. I'd backport the fix (it's super simple), but that regression needs to be taken care of first.

@scabug
Copy link
Author

scabug commented Mar 30, 2013

Leonard Schneider (leonard.schneider) said:
Thanks Eugene. In the meantime I've found a dirty hack not to be completely blocked.

@scabug
Copy link
Author

scabug commented Apr 28, 2013

@xeno-by said:
Now the fix is for real: scala/scala#2464

@scabug
Copy link
Author

scabug commented May 5, 2013

@xeno-by said:
Updated PR: scala/scala#2494

@scabug
Copy link
Author

scabug commented May 11, 2013

@xeno-by said:
Fixed in scala/scala@90ac5c4

@scabug scabug closed this as completed May 11, 2013
@scabug
Copy link
Author

scabug commented May 11, 2013

@xeno-by said:
Also see #7470

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

No branches or pull requests

2 participants