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

Crash with "bad position" in applyDynamic rewrite #8459

Closed
scabug opened this issue Mar 28, 2014 · 4 comments
Closed

Crash with "bad position" in applyDynamic rewrite #8459

scabug opened this issue Mar 28, 2014 · 4 comments

Comments

@scabug
Copy link

scabug commented Mar 28, 2014

I get a crash in the type checker when asking for completions after the dot of a class that extends Dynamic.

import scala.language.dynamics

class F extends Dynamic {
  def applyDynamic(name: String)(args: Any*) =
    s"method '$name' called with arguments ${args.mkString("'", "', '", "'")}"
}

class Foo {
  val bar = new F
  
  bar. // ask for completion, with nothing after the dot
}

stack trace:

java.lang.RuntimeException: bad position: [251:250]
	at scala.sys.package$.error(package.scala:27)
	at scala.reflect.internal.util.RangePosition.<init>(Position.scala:273)
	at scala.reflect.internal.util.RangePosition.withStart(Position.scala:278)
	at scala.reflect.internal.util.RangePosition.withStart(Position.scala:271)
	at scala.tools.nsc.typechecker.Typers$Typer$dyna$.mkInvoke(Typers.scala:4063)
	at scala.tools.nsc.typechecker.Typers$Typer.asDynamicCall$1(Typers.scala:4789)
	at scala.tools.nsc.typechecker.Typers$Typer.handleMissing$1(Typers.scala:4817)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedSelect$1(Typers.scala:4846)
	at scala.tools.nsc.typechecker.Typers$Typer.typedSelectOrSuperCall$1(Typers.scala:4933)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5563)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5642)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2928)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$61.apply(Typers.scala:3032)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$61.apply(Typers.scala:3032)
	at scala.collection.immutable.List.loop$1(List.scala:170)
	at scala.collection.immutable.List.mapConserve(List.scala:186)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3032)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1919)
	at scala.tools.nsc.typechecker.Typers$Typer.typedClassDef(Typers.scala:1759)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5583)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5642)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2928)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$61.apply(Typers.scala:3032)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$61.apply(Typers.scala:3032)
	at scala.collection.immutable.List.loop$1(List.scala:170)
	at scala.collection.immutable.List.mapConserve(List.scala:186)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3032)
	at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:5301)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5587)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5642)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5704)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:99)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:464)
	at scala.tools.nsc.interactive.Global$TyperRun$$anonfun$applyPhase$1.apply(Global.scala:1173)
	at scala.tools.nsc.interactive.Global$TyperRun$$anonfun$applyPhase$1.apply(Global.scala:1173)
	at scala.reflect.internal.SymbolTable.atPhase(SymbolTable.scala:207)
	at scala.tools.nsc.interactive.Global$TyperRun.applyPhase(Global.scala:1173)
	at scala.tools.nsc.interactive.Global$TyperRun.typeCheck(Global.scala:1166)
	at scala.tools.nsc.interactive.Global.scala$tools$nsc$interactive$Global$$typeCheck(Global.scala:592)
	at scala.tools.nsc.interactive.Global.scala$tools$nsc$interactive$Global$$typedTreeAt(Global.scala:741)
	at scala.tools.nsc.interactive.Global.scala$tools$nsc$interactive$Global$$scopeMembers(Global.scala:952)
	at scala.tools.nsc.interactive.Global$$anonfun$getScopeCompletion$2.apply(Global.scala:907)
	at scala.tools.nsc.interactive.Global$$anonfun$getScopeCompletion$2.apply(Global.scala:907)
	at scala.tools.nsc.interactive.Global$$anonfun$respond$1.apply(Global.scala:623)
	at scala.tools.nsc.interactive.Global$$anonfun$respond$1.apply(Global.scala:623)
	at scala.tools.nsc.interactive.Global.respondGradually(Global.scala:630)
	at scala.tools.nsc.interactive.Global.respond(Global.scala:623)
	at scala.tools.nsc.interactive.Global.getScopeCompletion(Global.scala:907)
	at scala.tools.nsc.interactive.CompilerControl$AskScopeCompletionItem.apply$mcV$sp(CompilerControl.scala:378)
	at scala.tools.nsc.interactive.Global.pollForWork(Global.scala:395)
	at scala.tools.nsc.interactive.PresentationCompilerThread.run(PresentationCompilerThread.scala:22)
@scabug
Copy link
Author

scabug commented Mar 28, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8459?orig=1
Reporter: @dragos
Affected Versions: 2.10.4

@scabug
Copy link
Author

scabug commented Sep 15, 2014

@ghik said (edited on Sep 15, 2014 2:14:54 PM UTC):
This affects selectDynamic, too.

@scabug
Copy link
Author

scabug commented Sep 16, 2014

@ghik said:
This fails with an AssertionError in 2.11

Exception in thread "main" java.lang.AssertionError: assertion failed: bad position: [225:224]
	at scala.reflect.internal.util.Position$.validate(Position.scala:34)
	at scala.reflect.internal.util.Position$.range(Position.scala:51)
	at scala.reflect.internal.util.InternalPositionImpl$class.copyRange(Position.scala:205)
	at scala.reflect.internal.util.InternalPositionImpl$class.withStart(Position.scala:124)
	at scala.reflect.internal.util.Position.withStart(Position.scala:12)
	at scala.tools.nsc.typechecker.Typers$Typer$dyna$.mkInvoke(Typers.scala:3962)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$asDynamicCall$1(Typers.scala:4614)
	at scala.tools.nsc.typechecker.Typers$Typer.handleMissing$1(Typers.scala:4659)
	at scala.tools.nsc.typechecker.Typers$Typer.typedSelectInternal$1(Typers.scala:4664)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedSelect$1(Typers.scala:4596)
	at scala.tools.nsc.typechecker.Typers$Typer.typedSelectOrSuperCall$1(Typers.scala:4735)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5253)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5269)
	at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5305)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5332)
	at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5279)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5283)
	at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5361)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:3000)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3104)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3104)
	at scala.collection.immutable.List.loop$1(List.scala:172)
	at scala.collection.immutable.List.mapConserve(List.scala:188)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3104)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1907)
	at scala.tools.nsc.typechecker.Typers$Typer.typedClassDef(Typers.scala:1753)
	at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5218)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5268)
	at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5305)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5332)
	at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5279)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5283)
	at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5361)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:3000)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3104)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3104)
	at scala.collection.immutable.List.loop$1(List.scala:172)
	at scala.collection.immutable.List.mapConserve(List.scala:188)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3104)
	at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:4928)
	at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5221)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5268)
	at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5305)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5332)
	at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5279)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5283)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5357)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:102)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:430)
	at scala.tools.nsc.interactive.Global$TyperRun$$anonfun$applyPhase$1.apply(Global.scala:1217)
	at scala.tools.nsc.interactive.Global$TyperRun$$anonfun$applyPhase$1.apply(Global.scala:1217)
	at scala.reflect.internal.SymbolTable.enteringPhase(SymbolTable.scala:242)
	at scala.tools.nsc.interactive.Global$TyperRun.applyPhase(Global.scala:1217)
	at scala.tools.nsc.interactive.Global$TyperRun.typeCheck(Global.scala:1210)
	at scala.tools.nsc.interactive.Global.scala$tools$nsc$interactive$Global$$typeCheck(Global.scala:659)
	at scala.tools.nsc.interactive.Global.typedTree(Global.scala:825)
	at scala.tools.nsc.interactive.Global$$anonfun$getTypedTree$1.apply(Global.scala:837)
	at scala.tools.nsc.interactive.Global$$anonfun$getTypedTree$1.apply(Global.scala:837)
	at scala.tools.nsc.interactive.Global$$anonfun$respond$1.apply(Global.scala:690)
	at scala.tools.nsc.interactive.Global$$anonfun$respond$1.apply(Global.scala:690)
	at scala.tools.nsc.interactive.Global.respondGradually(Global.scala:697)
	at scala.tools.nsc.interactive.Global.respond(Global.scala:690)
	at scala.tools.nsc.interactive.Global.getTypedTree(Global.scala:837)
	at scala.tools.nsc.interactive.Global.waitLoadedTyped(Global.scala:1152)
	at scala.tools.nsc.interactive.Global.waitLoadedTyped(Global.scala:1162)
	at scala.tools.nsc.interactive.CompilerControl$AskLoadedTypedItem.apply$mcV$sp(CompilerControl.scala:384)
	at scala.tools.nsc.interactive.Global$$anonfun$pollForWork$1.apply$mcV$sp(Global.scala:495)
	at scala.util.control.Breaks.breakable(Breaks.scala:38)
	at scala.tools.nsc.interactive.Global.pollForWork(Global.scala:420)
	at scala.tools.nsc.interactive.PresentationCompilerThread.run(PresentationCompilerThread.scala:22)

@scabug
Copy link
Author

scabug commented Sep 17, 2014

@ghik said:
scala/scala#3988

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