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

resetLocalAttrs followed by typeCheck causes error #7377

Closed
scabug opened this issue Apr 16, 2013 · 5 comments
Closed

resetLocalAttrs followed by typeCheck causes error #7377

scabug opened this issue Apr 16, 2013 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Apr 16, 2013

This is a regression; it works fine in 2.10.0 but is broken in 2.10.1.

Given this macro definition which does nothing but resetLocalAttrs and then typeCheck the result:

def noop[A](expr: A): A = macro noopImpl[A]  
def noopImpl[A](c: Context)(expr: c.Expr[A]): c.Expr[A] = c.Expr(c.typeCheck(c.resetLocalAttrs(expr.tree)))

If you try to use it you'll get an error:

scala> noop(List(1) match { case Nil => 0; case (x::xs) => x })
error: exception during macro expansion:
scala.reflect.macros.TypecheckException: not found: value _
	at scala.reflect.macros.runtime.Typers$$anonfun$typeCheck$2.apply(Typers.scala:31)
	at scala.reflect.macros.runtime.Typers$$anonfun$typeCheck$2.apply(Typers.scala:25)
	at scala.tools.nsc.typechecker.Contexts$Context.withMacrosEnabled(Contexts.scala:240)
	at scala.reflect.macros.runtime.Typers$$anonfun$3.apply(Typers.scala:18)
	at scala.reflect.macros.runtime.Typers$$anonfun$3.apply(Typers.scala:18)
	at scala.reflect.macros.runtime.Typers$$anonfun$wrapper$1$1.apply(Typers.scala:19)
	at scala.reflect.macros.runtime.Typers$$anonfun$wrapper$1$1.apply(Typers.scala:19)
	at scala.tools.nsc.typechecker.Contexts$Context.withImplicitsEnabled(Contexts.scala:209)
	at scala.reflect.macros.runtime.Typers$$anonfun$1.apply(Typers.scala:17)
	at scala.reflect.macros.runtime.Typers$$anonfun$1.apply(Typers.scala:17)
	at scala.reflect.macros.runtime.Typers$class.wrapper$1(Typers.scala:19)
	at scala.reflect.macros.runtime.Typers$class.typeCheck(Typers.scala:25)
	at scala.reflect.macros.runtime.Context.typeCheck(Context.scala:6)
	at scala.reflect.macros.runtime.Context.typeCheck(Context.scala:6)
	at monadsyntax.package$.noopImpl(package.scala:12)

It looks like possibly related to #5464, but seems distinct in that it is a regression.

@scabug
Copy link
Author

@scabug scabug commented Apr 16, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7377?orig=1
Reporter: Thomas Crockett (pelotom)
Affected Versions: 2.10.1

@scabug
Copy link
Author

@scabug scabug commented Apr 16, 2013

@xeno-by said:
Is this urgent? If yes, I'll take a look asap, otherwise I'd prefer to investigate later.

@scabug
Copy link
Author

@scabug scabug commented Apr 16, 2013

Thomas Crockett (pelotom) said:
Not urgent, I can use 2.10.0 in the meantime, thanks.

@scabug
Copy link
Author

@scabug scabug commented Apr 16, 2013

@retronym said:
Some breadcrumbs:

def normalTypedApply(tree: Tree, fun: Tree, args: List[Tree]) = {
        val stableApplication = (fun.symbol ne null) && fun.symbol.isMethod && fun.symbol.isStable
        if (stableApplication && isPatternMode) {
          // treat stable function applications f() as expressions.
          typed1(tree, mode & ~PATTERNmode | EXPRmode, pt)
        
     def typedIdentOrWildcard(tree: Ident) = {
        val name = tree.name
        if (Statistics.canEnable) Statistics.incCounter(typedIdentCount)
        if ((name == nme.WILDCARD && (mode & (PATTERNmode | FUNmode)) == PATTERNmode) ||
            (name == tpnme.WILDCARD && (mode & TYPEmode) != 0))
          tree setType makeFullyDefined(pt)
        else
          typedIdent(tree, name)
      }

In the original type check, we get to:

normalTypedApply(tree = << ::((x @ _), (xs @ _)) >>, fun = << :: >>, ...)

After a reset, the retypecheck gets to:

normalTypedApply(tree = << scala.`package`.::((x @ _), (xs @ _)) >>, fun = << scala.`package`.:: >>, ...)

The function is treated as a stable application, and the application is typed in expression mode, rather than pattern mode. Under this mode, the ident _ does not typecheck.

I'm not sure yet what changed from 2.10.0 to 2.10.1 to lead us down this path.

@scabug
Copy link
Author

@scabug scabug commented Apr 17, 2013

@scabug scabug closed this Apr 19, 2013
@scabug scabug added this to the 2.10.2-RC1 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants