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

Compiler crash because of method <> object overloading #11415

Open
Jasper-M opened this Issue Feb 25, 2019 · 4 comments

Comments

Projects
None yet
4 participants
@Jasper-M
Copy link
Member

Jasper-M commented Feb 25, 2019

scala> class Foo { def A(i: Int) = i; object A{ def apply(i: Int) = i+1 }; def foo = A(0) }
scala.ScalaReflectionException: object A is not a method
	at scala.reflect.api.Symbols$SymbolApi.asMethod(Symbols.scala:240)
	at scala.reflect.api.Symbols$SymbolApi.asMethod$(Symbols.scala:234)
	at scala.reflect.internal.Symbols$SymbolContextApiImpl.asMethod(Symbols.scala:106)
	at scala.tools.nsc.typechecker.ContextErrors$InferencerContextErrors$InferErrorGen$.AmbiguousMethodAlternativeError(ContextErrors.scala:1132)
	at scala.tools.nsc.typechecker.Infer$Inferencer$InferMethodAlternativeTwice$1.bestForExpectedType(Infer.scala:1445)
	at scala.tools.nsc.typechecker.Infer$Inferencer$InferMethodAlternativeTwice$1.tryOnce(Infer.scala:1455)
	at scala.tools.nsc.typechecker.Contexts$Context$TryTwice.$anonfun$apply$1(Contexts.scala:554)
	at scala.tools.nsc.typechecker.Contexts$Context$TryTwice.apply(Contexts.scala:622)
	at scala.tools.nsc.typechecker.Infer$Inferencer.inferMethodAlternative(Infer.scala:1459)
	at scala.tools.nsc.typechecker.Typers$Typer.handleOverloaded$1(Typers.scala:3544)
	at scala.tools.nsc.typechecker.Typers$Typer.doTypedApply(Typers.scala:3548)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typed1$26(Typers.scala:4840)
	at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:712)
	at scala.tools.nsc.typechecker.Typers$Typer.tryTypedApply$1(Typers.scala:4840)
	at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4924)
	at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4935)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5795)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5841)
	at scala.tools.nsc.typechecker.Typers$Typer.computeType(Typers.scala:5916)
	at scala.tools.nsc.typechecker.Namers$Namer.assignTypeToTree(Namers.scala:1121)
	at scala.tools.nsc.typechecker.Namers$Namer.methodSig(Namers.scala:1439)
	at scala.tools.nsc.typechecker.Namers$Namer.memberSig(Namers.scala:1884)
	at scala.tools.nsc.typechecker.Namers$Namer.typeSig(Namers.scala:1849)
	at scala.tools.nsc.typechecker.Namers$Namer$MonoTypeCompleter.completeImpl(Namers.scala:868)
	at scala.tools.nsc.typechecker.Namers$LockingTypeCompleter.complete(Namers.scala:2034)
	at scala.tools.nsc.typechecker.Namers$LockingTypeCompleter.complete$(Namers.scala:2032)
	at scala.tools.nsc.typechecker.Namers$TypeCompleterBase.complete(Namers.scala:2027)
	at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1542)
	at scala.reflect.internal.Symbols$Symbol.initialize(Symbols.scala:1690)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5442)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5841)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:5905)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedStats$10(Typers.scala:3393)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3393)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:2046)
	at scala.tools.nsc.typechecker.Typers$Typer.typedClassDef(Typers.scala:1876)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5751)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5841)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:5905)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedStats$10(Typers.scala:3393)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3393)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:2046)
	at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1921)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5752)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5841)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:5905)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedStats$10(Typers.scala:3393)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3393)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:2046)
	at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1921)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5752)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5841)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:5905)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedStats$10(Typers.scala:3393)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3393)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:2046)
	at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1921)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5752)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5841)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:5905)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedStats$10(Typers.scala:3393)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3393)
	at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:5451)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5754)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5841)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$TyperPhase.apply(Analyzer.scala:115)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:447)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$TyperPhase.run(Analyzer.scala:104)
	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1508)
	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1492)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compile(IMain.scala:707)
	at scala.tools.nsc.interpreter.IMain$Request.compile(IMain.scala:898)
	at scala.tools.nsc.interpreter.IMain.compile(IMain.scala:496)
	at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:490)
	at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:473)
	at scala.tools.nsc.interpreter.shell.ILoop.interpretStartingWith(ILoop.scala:933)
	at scala.tools.nsc.interpreter.shell.ILoop.command(ILoop.scala:790)
	at scala.tools.nsc.interpreter.shell.ILoop.processLine(ILoop.scala:465)
	at scala.tools.nsc.interpreter.shell.ILoop.loop(ILoop.scala:488)
	at scala.tools.nsc.interpreter.shell.ILoop.run(ILoop.scala:1022)
	at xsbt.ConsoleInterface.run(ConsoleInterface.scala:74)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sbt.internal.inc.AnalyzingCompiler.call(AnalyzingCompiler.scala:237)
	at sbt.internal.inc.AnalyzingCompiler.console(AnalyzingCompiler.scala:199)
	at sbt.Console.console0$1(Console.scala:48)
	at sbt.Console.$anonfun$apply$2(Console.scala:51)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:10)
	at sbt.TrapExit$App.run(TrapExit.scala:253)
	at java.lang.Thread.run(Thread.java:748)

It's possible to get a different error message, but AFAICT the stacktrace is exactly the same.

scala> class Foo { def A(i: Int) = i; object A{ def apply(i: Int) = i+1 } }
defined class Foo

scala> new Foo().A(0)
scala.ScalaReflectionException: object A encapsulates multiple overloaded alternatives and cannot be treated as a method. Consider invoking `<offending symbol>.asTerm.alternatives` and manually picking the required method
	at scala.reflect.api.Symbols$SymbolApi.asMethod(Symbols.scala:240)
        ...
@SethTisue

This comment has been minimized.

Copy link
Member

SethTisue commented Feb 25, 2019

in what Scala version?

@Jasper-M

This comment has been minimized.

Copy link
Member Author

Jasper-M commented Feb 25, 2019

Yeah sorry. The stacktrace here is from a recent snapshot version of 2.13. I think the crash was the same on 2.12.8.

@SethTisue SethTisue added this to the Backlog milestone Feb 25, 2019

@Jasper-M

This comment has been minimized.

Copy link
Member Author

Jasper-M commented Feb 27, 2019

I think the crash was the same on 2.12.8.

@SethTisue I was wrong. It's a regression in 2.13.
2.12.8 prints a beautiful (though slightly inaccurate) error message:

error: ambiguous reference to overloaded definition,
both object A in class Foo of type Foo.this.A.type
and  method A in class Foo of type (i: Int)Int
match argument types (Int)

@SethTisue SethTisue modified the milestones: Backlog, 2.13.0-RC1 Feb 27, 2019

@SethTisue

This comment has been minimized.

Copy link
Member

SethTisue commented Feb 27, 2019

thanks. I've put it on the RC1 milestone for evaluation, but my guess is that @adriaanm or @retronym will move it back to "Backlog"

@adriaanm adriaanm self-assigned this Feb 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.