Valid code cannot be opened with Scala editor
Hi,
I've attached 3 rather simple scala files. When I create a new Scala project that contains just these 3 files, they compile fine. However, when I double-click the file "Throwing.scala" in Eclipse's package explorer, the Scala editor fails to open:
"Could not open the editor: Editor could not be initialized."
java.lang.Error: A in trait Throwing cannot be instantiated from Throwing[A] with A
at scala.tools.nsc.symtab.SymbolTable.abort(SymbolTable.scala:35)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.throwError$1(Types.scala:3389)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.instParam$1(Types.scala:3392)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.toInstance$1(Types.scala:3404)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3420)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3289)
at scala.collection.immutable.List.loop$1(List.scala:117)
at scala.collection.immutable.List.mapConserve(List.scala:133)
at scala.tools.nsc.symtab.Types$TypeMap.mapOver(Types.scala:3066)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3422)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3289)
at scala.tools.nsc.symtab.Types$TypeMap.mapOver(Types.scala:3056)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3422)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3289)
at scala.tools.nsc.symtab.Types$TypeMap$$anonfun$16.apply(Types.scala:3132)
at scala.tools.nsc.symtab.Types$TypeMap$$anonfun$16.apply(Types.scala:3129)
at scala.collection.LinearSeqOptimized$class.exists(LinearSeqOptimized.scala:79)
at scala.collection.immutable.List.exists(List.scala:45)
at scala.tools.nsc.symtab.Types$TypeMap.mapOver(Types.scala:3129)
at scala.tools.nsc.symtab.Types$TypeMap.mapOver(Types.scala:3072)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3422)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3289)
at scala.tools.nsc.symtab.Types$TypeMap.mapOver(Types.scala:3033)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3422)
at scala.tools.nsc.symtab.Types$Type.asSeenFrom(Types.scala:544)
at scala.tools.nsc.symtab.Types$Type.computeMemberType(Types.scala:573)
at scala.tools.nsc.symtab.Symbols$MethodSymbol.typeAsMemberOf(Symbols.scala:1806)
at scala.tools.nsc.symtab.Types$Type.memberType(Types.scala:564)
at scala.tools.nsc.symtab.Symbols$Symbol$$anonfun$matchingSymbol$1.apply(Symbols.scala:1383)
at scala.tools.nsc.symtab.Symbols$Symbol$$anonfun$matchingSymbol$1.apply(Symbols.scala:1382)
at scala.tools.nsc.symtab.Symbols$Symbol.filter(Symbols.scala:1052)
at scala.tools.nsc.symtab.Symbols$Symbol.matchingSymbol(Symbols.scala:1382)
at scala.tools.nsc.symtab.Symbols$Symbol.overriddenSymbol(Symbols.scala:1395)
at scala.tools.nsc.symtab.Symbols$Symbol$$anonfun$allOverriddenSymbols$1.apply(Symbols.scala:1405)
at scala.tools.nsc.symtab.Symbols$Symbol$$anonfun$allOverriddenSymbols$1.apply(Symbols.scala:1405)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
at scala.collection.immutable.List.map(List.scala:45)
at scala.tools.nsc.symtab.Symbols$Symbol.allOverriddenSymbols(Symbols.scala:1405)
at scala.tools.eclipse.javaelements.ScalaOverrideIndicatorBuilder$OverrideIndicatorBuilderTraverser.traverse(ScalaOverrideIndicatorBuilder.scala:61)
at scala.tools.nsc.ast.Trees$Traverser$$anonfun$traverseStats$1.apply(Trees.scala:922)
at scala.tools.nsc.ast.Trees$Traverser$$anonfun$traverseStats$1.apply(Trees.scala:920)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.tools.nsc.ast.Trees$Traverser.traverseStats(Trees.scala:920)
at scala.tools.nsc.ast.Trees$Traverser.traverseStats(Trees.scala:899)
at scala.reflect.generic.Trees$Traverser.traverse(Trees.scala:491)
at scala.tools.nsc.ast.Trees$Traverser.traverse(Trees.scala:914)
at scala.tools.eclipse.javaelements.ScalaOverrideIndicatorBuilder$OverrideIndicatorBuilderTraverser.traverse(ScalaOverrideIndicatorBuilder.scala:78)
at scala.reflect.generic.Trees$Traverser$$anonfun$traverse$2.apply$mcV$sp(Trees.scala:464)
at scala.reflect.generic.Trees$Traverser.atOwner(Trees.scala:576)
at scala.reflect.generic.Trees$Traverser.traverse(Trees.scala:463)
at scala.tools.nsc.ast.Trees$Traverser.traverse(Trees.scala:914)
at scala.tools.eclipse.javaelements.ScalaOverrideIndicatorBuilder$OverrideIndicatorBuilderTraverser.traverse(ScalaOverrideIndicatorBuilder.scala:78)
at scala.reflect.generic.Trees$Traverser$$anonfun$traverseTrees$1.apply(Trees.scala:561)
at scala.reflect.generic.Trees$Traverser$$anonfun$traverseTrees$1.apply(Trees.scala:561)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.reflect.generic.Trees$Traverser.traverseTrees(Trees.scala:561)
at scala.reflect.generic.Trees$Traverser$$anonfun$traverse$1.apply$mcV$sp(Trees.scala:460)
at scala.reflect.generic.Trees$Traverser.atOwner(Trees.scala:576)
at scala.reflect.generic.Trees$Traverser.traverse(Trees.scala:459)
at scala.tools.nsc.ast.Trees$Traverser.traverse(Trees.scala:914)
at scala.tools.eclipse.javaelements.ScalaOverrideIndicatorBuilder$OverrideIndicatorBuilderTraverser.traverse(ScalaOverrideIndicatorBuilder.scala:78)
at scala.tools.eclipse.javaelements.ScalaCompilationUnit$$anonfun$createOverrideIndicators$1$$anonfun$apply$7$$anonfun$apply$3.apply$mcV$sp(ScalaCompilationUnit.scala:136)
at scala.tools.eclipse.javaelements.ScalaCompilationUnit$$anonfun$createOverrideIndicators$1$$anonfun$apply$7$$anonfun$apply$3.apply(ScalaCompilationUnit.scala:135)
at scala.tools.eclipse.javaelements.ScalaCompilationUnit$$anonfun$createOverrideIndicators$1$$anonfun$apply$7$$anonfun$apply$3.apply(ScalaCompilationUnit.scala:135)
at scala.tools.nsc.util.InterruptReq.liftedTree1$1(InterruptReq.scala:20)
at scala.tools.nsc.util.InterruptReq.execute(InterruptReq.scala:19)
at scala.tools.nsc.interactive.Global.pollForWork(Global.scala:305)
at scala.tools.nsc.interactive.PresentationCompilerThread.run(PresentationCompilerThread.scala:25)
To me, this looks a bit similar to bug #1000337 but the difference here (for me at least) is, that the code compiles fine but causes trouble in the presentation compiler.
Kind regards
Andreas
---
Eclipse IDE for Java Developers
Version: Helios Service Release 2
Build id: 20110301-1815
(also happens on the Mac using the latest Eclipse Classic)
Scala IDE for Eclipse 2.0.0.201103281820-beta1-316ca33 org.scala-ide.sdt.feature.feature.group
I've attached 3 rather simple scala files. When I create a new Scala project that contains just these 3 files, they compile fine. However, when I double-click the file "Throwing.scala" in Eclipse's package explorer, the Scala editor fails to open:
"Could not open the editor: Editor could not be initialized."
java.lang.Error: A in trait Throwing cannot be instantiated from Throwing[A] with A
at scala.tools.nsc.symtab.SymbolTable.abort(SymbolTable.scala:35)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.throwError$1(Types.scala:3389)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.instParam$1(Types.scala:3392)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.toInstance$1(Types.scala:3404)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3420)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3289)
at scala.collection.immutable.List.loop$1(List.scala:117)
at scala.collection.immutable.List.mapConserve(List.scala:133)
at scala.tools.nsc.symtab.Types$TypeMap.mapOver(Types.scala:3066)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3422)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3289)
at scala.tools.nsc.symtab.Types$TypeMap.mapOver(Types.scala:3056)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3422)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3289)
at scala.tools.nsc.symtab.Types$TypeMap$$anonfun$16.apply(Types.scala:3132)
at scala.tools.nsc.symtab.Types$TypeMap$$anonfun$16.apply(Types.scala:3129)
at scala.collection.LinearSeqOptimized$class.exists(LinearSeqOptimized.scala:79)
at scala.collection.immutable.List.exists(List.scala:45)
at scala.tools.nsc.symtab.Types$TypeMap.mapOver(Types.scala:3129)
at scala.tools.nsc.symtab.Types$TypeMap.mapOver(Types.scala:3072)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3422)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3289)
at scala.tools.nsc.symtab.Types$TypeMap.mapOver(Types.scala:3033)
at scala.tools.nsc.symtab.Types$AsSeenFromMap.apply(Types.scala:3422)
at scala.tools.nsc.symtab.Types$Type.asSeenFrom(Types.scala:544)
at scala.tools.nsc.symtab.Types$Type.computeMemberType(Types.scala:573)
at scala.tools.nsc.symtab.Symbols$MethodSymbol.typeAsMemberOf(Symbols.scala:1806)
at scala.tools.nsc.symtab.Types$Type.memberType(Types.scala:564)
at scala.tools.nsc.symtab.Symbols$Symbol$$anonfun$matchingSymbol$1.apply(Symbols.scala:1383)
at scala.tools.nsc.symtab.Symbols$Symbol$$anonfun$matchingSymbol$1.apply(Symbols.scala:1382)
at scala.tools.nsc.symtab.Symbols$Symbol.filter(Symbols.scala:1052)
at scala.tools.nsc.symtab.Symbols$Symbol.matchingSymbol(Symbols.scala:1382)
at scala.tools.nsc.symtab.Symbols$Symbol.overriddenSymbol(Symbols.scala:1395)
at scala.tools.nsc.symtab.Symbols$Symbol$$anonfun$allOverriddenSymbols$1.apply(Symbols.scala:1405)
at scala.tools.nsc.symtab.Symbols$Symbol$$anonfun$allOverriddenSymbols$1.apply(Symbols.scala:1405)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
at scala.collection.immutable.List.map(List.scala:45)
at scala.tools.nsc.symtab.Symbols$Symbol.allOverriddenSymbols(Symbols.scala:1405)
at scala.tools.eclipse.javaelements.ScalaOverrideIndicatorBuilder$OverrideIndicatorBuilderTraverser.traverse(ScalaOverrideIndicatorBuilder.scala:61)
at scala.tools.nsc.ast.Trees$Traverser$$anonfun$traverseStats$1.apply(Trees.scala:922)
at scala.tools.nsc.ast.Trees$Traverser$$anonfun$traverseStats$1.apply(Trees.scala:920)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.tools.nsc.ast.Trees$Traverser.traverseStats(Trees.scala:920)
at scala.tools.nsc.ast.Trees$Traverser.traverseStats(Trees.scala:899)
at scala.reflect.generic.Trees$Traverser.traverse(Trees.scala:491)
at scala.tools.nsc.ast.Trees$Traverser.traverse(Trees.scala:914)
at scala.tools.eclipse.javaelements.ScalaOverrideIndicatorBuilder$OverrideIndicatorBuilderTraverser.traverse(ScalaOverrideIndicatorBuilder.scala:78)
at scala.reflect.generic.Trees$Traverser$$anonfun$traverse$2.apply$mcV$sp(Trees.scala:464)
at scala.reflect.generic.Trees$Traverser.atOwner(Trees.scala:576)
at scala.reflect.generic.Trees$Traverser.traverse(Trees.scala:463)
at scala.tools.nsc.ast.Trees$Traverser.traverse(Trees.scala:914)
at scala.tools.eclipse.javaelements.ScalaOverrideIndicatorBuilder$OverrideIndicatorBuilderTraverser.traverse(ScalaOverrideIndicatorBuilder.scala:78)
at scala.reflect.generic.Trees$Traverser$$anonfun$traverseTrees$1.apply(Trees.scala:561)
at scala.reflect.generic.Trees$Traverser$$anonfun$traverseTrees$1.apply(Trees.scala:561)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.reflect.generic.Trees$Traverser.traverseTrees(Trees.scala:561)
at scala.reflect.generic.Trees$Traverser$$anonfun$traverse$1.apply$mcV$sp(Trees.scala:460)
at scala.reflect.generic.Trees$Traverser.atOwner(Trees.scala:576)
at scala.reflect.generic.Trees$Traverser.traverse(Trees.scala:459)
at scala.tools.nsc.ast.Trees$Traverser.traverse(Trees.scala:914)
at scala.tools.eclipse.javaelements.ScalaOverrideIndicatorBuilder$OverrideIndicatorBuilderTraverser.traverse(ScalaOverrideIndicatorBuilder.scala:78)
at scala.tools.eclipse.javaelements.ScalaCompilationUnit$$anonfun$createOverrideIndicators$1$$anonfun$apply$7$$anonfun$apply$3.apply$mcV$sp(ScalaCompilationUnit.scala:136)
at scala.tools.eclipse.javaelements.ScalaCompilationUnit$$anonfun$createOverrideIndicators$1$$anonfun$apply$7$$anonfun$apply$3.apply(ScalaCompilationUnit.scala:135)
at scala.tools.eclipse.javaelements.ScalaCompilationUnit$$anonfun$createOverrideIndicators$1$$anonfun$apply$7$$anonfun$apply$3.apply(ScalaCompilationUnit.scala:135)
at scala.tools.nsc.util.InterruptReq.liftedTree1$1(InterruptReq.scala:20)
at scala.tools.nsc.util.InterruptReq.execute(InterruptReq.scala:19)
at scala.tools.nsc.interactive.Global.pollForWork(Global.scala:305)
at scala.tools.nsc.interactive.PresentationCompilerThread.run(PresentationCompilerThread.scala:25)
To me, this looks a bit similar to bug #1000337 but the difference here (for me at least) is, that the code compiles fine but causes trouble in the presentation compiler.
Kind regards
Andreas
---
Eclipse IDE for Java Developers
Version: Helios Service Release 2
Build id: 20110301-1815
(also happens on the Mac using the latest Eclipse Classic)
Scala IDE for Eclipse 2.0.0.201103281820-beta1-316ca33 org.scala-ide.sdt.feature.feature.group
Leave a comment
(In revision:3e397d44dd6e7b30edbf791413961ba95f76a2c5) Fixed #1000350, fixed #1000326. Catch exceptions thrown during override
indicators building (errors in the source file may trick the compiler into crashing while looking at overridden methods.
Branch:wip_experiment
indicators building (errors in the source file may trick the compiler into crashing while looking at overridden methods.
Branch:wip_experiment
on 2011-04-05 16:13 *
By David Bernard
(In revision:a542512d9bf28965ea85966c5ddab88fa7bfa247) port of Fixed #1000350, fixed #1000326. Catch exceptions thrown during override indicators building (errors in the source file may trick the compiler into crashing while looking at overridden methods.
Branch:wip_exp_backport
Branch:wip_exp_backport
on 2011-04-05 16:54 *
By Andreas Flierl
Sorry if I'm being too sceptical, but why should the presentation compiler crash on code that compiles fine, i.e. contains no errors?
on 2011-04-06 02:49 *
By Andreas Flierl
With the latest nightly, the editor now opens again and the above exception is logged to the error log (but still there...). Also, the method "throwAtPerson" bears a green "override indicator" although it overrides nothing. So, while the situation has certainly improved tremendously with your fix, the problem at the core is still there.
on 2011-04-06 02:51 *
By Iulian Dragos
In principle it shouldn't, but it impossible to guarantee it won't. So to reverse the question, why should the editor stop working if the override indicators can't be placed? :-)
The long answer is that for override indicators and structure building we don't wait for a full type check (that can take way too long to look responsive). Instead, we do a parse and enter symbols, whose types are lazily computed (type checking only what's needed). It seems in more complicated code this could fail. However, it's very unlikely we'll switch back to full typechecking, so we have to live with (some) crashes. Note that once you start typing, full type checking is performed for 'report problems as you type', and this information (like the outline) is recomputed having all the information. If you type in your example, you'll notice no errors are logged in the Error Log.
I'll anyway see with Martin if he can fix this on the compiler side.
The long answer is that for override indicators and structure building we don't wait for a full type check (that can take way too long to look responsive). Instead, we do a parse and enter symbols, whose types are lazily computed (type checking only what's needed). It seems in more complicated code this could fail. However, it's very unlikely we'll switch back to full typechecking, so we have to live with (some) crashes. Note that once you start typing, full type checking is performed for 'report problems as you type', and this information (like the outline) is recomputed having all the information. If you type in your example, you'll notice no errors are logged in the Error Log.
I'll anyway see with Martin if he can fix this on the compiler side.
on 2011-04-06 02:52 *
By Iulian Dragos
(the full type check is done on the reconciler thread, so the user doesn't wait, while when opening the file it's a blocking operation).
on 2011-04-06 03:00 *
By Andreas Flierl
Thanks for taking the time for the explanation.
As for your reverse question: it shouldn't, of course. :)
I wasn't opposing your fix at all, I think failing gracefully here is miles better than not opening the editor. I just wanted to point at the compiler problem (again) because I feared it might have been overlooked, which it has not. At least it had the side effect that I now know a bit about the intricacies involved.
As for your reverse question: it shouldn't, of course. :)
I wasn't opposing your fix at all, I think failing gracefully here is miles better than not opening the editor. I just wanted to point at the compiler problem (again) because I feared it might have been overlooked, which it has not. At least it had the side effect that I now know a bit about the intricacies involved.
There are two bugs: the override indicator is there even after full typechecking, so that's a bug in the compiler (even after editing, the green triangle is still there). The other is the lazy computation of overridden symbols, which fails on incompletely typechecked trees. I reopen this bug so we don't forget about them.
on 2011-04-06 03:33 *
By Iulian Dragos
Sorry if I sounded annoyed, it's actually great you pushed for more information. I'll link back to the Scala ticket system once there is something. Both issues are linked to ticket 2808.
It has been fixed in the latest nightly of the Scala compiler. Thanks for pushing it, it revealed deeper issues in the language. The current nightly should fix both the exception in the Error Log and the invalid overriding indicator.
on 2011-04-08 04:25 *
By Andreas Flierl
Just tried it and it works fine. Thanks for your great work.
on 2011-04-14 15:53 *
By Iulian Dragos
(In revision:6dbe77c949ef251bf663e9a10c9c7fdca78f2b4e) Fixed #1000350, fixed #1000326. Catch exceptions thrown during override
indicators building (errors in the source file may trick the compiler into crashing while looking at overridden methods.
Branch:repl_wip
indicators building (errors in the source file may trick the compiler into crashing while looking at overridden methods.
Branch:repl_wip