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
Typechecking of a macro expansion infers wrong type for List.map #6155
Comments
Imported From: https://issues.scala-lang.org/browse/SI-6155?orig=1 |
@xeno-by said: immutable.this.List.apply[Int](1).map[Int, Any](((x: Int) => x))(immutable.this.List.canBuildFrom[Int]) Interestingly enough, c.typeCheck works correctly producing: immutable.this.List.apply[Int](1).map[Int, List[Int]](((x: Int) => x))(immutable.this.List.canBuildFrom[Int]) |
@xeno-by said: |
Kim Stebel (kimstebel) said: |
@xeno-by said (edited on Aug 11, 2012 10:10:12 AM UTC): When Therefore I suggest there's something wrong with the inferrer. |
@Blaisorblade said (edited on Aug 30, 2012 5:52:23 PM UTC): The following looks like an identity macro but isn't: def macroId(arg: Any) = macro macroId_impl
def macroId_impl(c: Context)(arg: c.Expr[Any]): c.Expr[Any] = arg for the same reason for which The correct version of the macro is: def macroId[T](arg: T): T = macro macroId_impl[T]
def macroId_impl[T: c.AbsTypeTag](c: Context)(arg: c.Expr[T]): c.Expr[T] = arg The problem could be reduced by having the typechecker special-case |
@Blaisorblade said: As Eugene said, macros are not at fault because type inference in this code does the same thing, in all calls to def id(x: Any): Any = x
id(List.apply(1).map((x: Int) => x))
val foo:Any = List.apply(1).map((x: Int) => x)
println(List.apply(1).map((x: Int) => x)) However, all that code works! What strikes me as odd is another thing. Given that def test(s:String) = macro testImpl
def testImpl(c:Context)(s:c.Expr[String]):c.Expr[Any] = ... why should one expect this code: val list:List[Int] = test("") to work? Why isn't it an error that it compiles, after adding the call to typecheck? Apparently, the macro output can statically refine the declared type - but how should this work, are there guarantees on that? I'm not sure anymore that this is a bug - unless you can point me to an explanation for users of how things are supposed to work, we might have a documentation bug here. |
@xeno-by said: |
@paulp said: class A {
def f1 = Vector(1,2,3) == List(1).map(_ + 1)
def f2 = Vector(1,2,3) equals List(1).map(_ + 1)
} The first map call infers List[Int] for the type argument, the second infers Any. Since I had already observed that arguments to overloaded targets are typed more accurately than arguments to not-overloaded targets, I looked and indeed 'def ==' is overloaded between Any and AnyRef whereas 'def equals' is overridden in AnyRef. |
@retronym said:
|
it's not clear to me if there's anything actionable here someone can reopen if they can clearly summarize the state of the ticket (or perhaps it would be better to open one or more new tickets) |
Following up on this comment of mine, the documentation issue has arguably been fixed. With blackbox macros, the original code is clearly ill-typed, because a function returning Instead, for whitebox macros, IIUC it's nowadays clear enough that "all bets are off", isn't it? So IIUC this isn't even a bug. |
As per http://stackoverflow.com/questions/11681631/macro-return-type-and-higher-order-functions:
Macro definition:
Macro call:
Error message:
The text was updated successfully, but these errors were encountered: