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

isPublic method throwing an exception #16175

Closed
tgodzik opened this issue Oct 12, 2022 · 5 comments
Closed

isPublic method throwing an exception #16175

tgodzik opened this issue Oct 12, 2022 · 5 comments

Comments

@tgodzik
Copy link
Contributor

tgodzik commented Oct 12, 2022

Compiler version

3.2.1-RC2

Minimized code

When Metals used the compiler it tries to load some symbols for classfiles to get automatic imports for symbols.

It seems there is an issue with shaded scala collection classfiles inside coursierapi.

//> using scala "3.2.1-RC2"
//> using lib "io.get-coursier:interface:1.0.9"

def main() =
    println("tree")

Most likely happening in this piece of code:
https://github.com/scalameta/metals/blob/main/mtags/src/main/scala-3/scala/meta/internal/pc/CompilerSearchVisitor.scala

Is it something we are doing or an issue with the compiler? Anyway I wouldn't expect isPublic method to throw an exception.

Output

java.lang.AssertionError: assertion failed: coursierapi.shaded.scala.collection.package$. already has a symbol
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
	at dotty.tools.dotc.core.SymbolLoaders$.enterNew(SymbolLoaders.scala:42)
	at dotty.tools.dotc.core.SymbolLoaders$.enterClass(SymbolLoaders.scala:53)
	at dotty.tools.dotc.core.SymbolLoaders$.enterClassAndModule(SymbolLoaders.scala:104)
	at dotty.tools.dotc.core.classfile.ClassfileParser.enterClassAndModule$1(ClassfileParser.scala:856)
	at dotty.tools.dotc.core.classfile.ClassfileParser.enterOwnInnerClasses$$anonfun$1(ClassfileParser.scala:864)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:575)
	at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:573)
	at dotty.tools.dotc.util.GenericHashMap$EntryIterator.foreach(GenericHashMap.scala:166)
	at dotty.tools.dotc.core.classfile.ClassfileParser.enterOwnInnerClasses(ClassfileParser.scala:864)
	at dotty.tools.dotc.core.classfile.ClassfileParser.parseClass(ClassfileParser.scala:200)
	at dotty.tools.dotc.core.classfile.ClassfileParser.$anonfun$1(ClassfileParser.scala:87)
	at dotty.tools.dotc.core.classfile.ClassfileParser.run(ClassfileParser.scala:82)
	at dotty.tools.dotc.core.ClassfileLoader.load(SymbolLoaders.scala:411)
	at dotty.tools.dotc.core.ClassfileLoader.doComplete(SymbolLoaders.scala:406)
	at dotty.tools.dotc.core.SymbolLoader$$anon$1.doComplete(SymbolLoaders.scala:325)
	at dotty.tools.dotc.core.SymbolLoader.complete(SymbolLoaders.scala:340)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:171)
	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeMembersNamed(SymDenotations.scala:2044)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamed(SymDenotations.scala:2014)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamedNoShadowingBasedOnFlags(SymDenotations.scala:2037)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.nonPrivateMembersNamed(SymDenotations.scala:2027)
	at dotty.tools.dotc.core.SymDenotations$PackageClassDenotation.recur$5(SymDenotations.scala:2391)
	at dotty.tools.dotc.core.SymDenotations$PackageClassDenotation.computeMembersNamed(SymDenotations.scala:2455)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamed(SymDenotations.scala:2014)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:2065)
	at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:686)
	at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:879)
	at dotty.tools.dotc.core.Types$Type.memberBasedOnFlags(Types.scala:669)
	at dotty.tools.dotc.core.Types$Type.member(Types.scala:653)
	at dotty.tools.dotc.core.Denotations$.select$1(Denotations.scala:1294)
	at dotty.tools.dotc.core.Denotations$.recurSimple$1(Denotations.scala:1324)
	at dotty.tools.dotc.core.Denotations$.recur$1(Denotations.scala:1326)
	at dotty.tools.dotc.core.Denotations$.staticRef$$anonfun$1(Denotations.scala:1331)
	at dotty.tools.dotc.util.GenericHashMap.getOrElseUpdate(GenericHashMap.scala:133)
	at dotty.tools.dotc.core.Denotations$.staticRef(Denotations.scala:1331)
	at dotty.tools.dotc.core.Symbols$.requiredClass(Symbols.scala:875)
	at dotty.tools.dotc.core.classfile.ClassfileParser.lookupTopLevel$1(ClassfileParser.scala:118)
	at dotty.tools.dotc.core.classfile.ClassfileParser.classNameToSymbol(ClassfileParser.scala:127)
	at dotty.tools.dotc.core.classfile.ClassfileParser.getClassSymbol(ClassfileParser.scala:1169)
	at dotty.tools.dotc.core.classfile.ClassfileParser$ConstantPool.getClassSymbol(ClassfileParser.scala:1236)
	at dotty.tools.dotc.core.classfile.ClassfileParser$ConstantPool.getSuperClass(ClassfileParser.scala:1285)
	at dotty.tools.dotc.core.classfile.ClassfileParser.parseParents$1(ClassfileParser.scala:180)
	at dotty.tools.dotc.core.classfile.ClassfileParser.parseClass(ClassfileParser.scala:196)
	at dotty.tools.dotc.core.classfile.ClassfileParser.$anonfun$1(ClassfileParser.scala:87)
	at dotty.tools.dotc.core.classfile.ClassfileParser.run(ClassfileParser.scala:82)
	at dotty.tools.dotc.core.ClassfileLoader.load(SymbolLoaders.scala:411)
	at dotty.tools.dotc.core.ClassfileLoader.doComplete(SymbolLoaders.scala:406)
	at dotty.tools.dotc.core.SymbolLoader.complete(SymbolLoaders.scala:340)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:171)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeOnce(SymDenotations.scala:365)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.unforcedDecls(SymDenotations.scala:389)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.typeParamsFromDecls(SymDenotations.scala:1794)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.typeParams(SymDenotations.scala:1807)
	at dotty.tools.dotc.core.classfile.ClassfileParser$$anon$2.apply(ClassfileParser.scala:38)
	at dotty.tools.dotc.core.classfile.ClassfileParser$$anon$2.apply(ClassfileParser.scala:37)
	at scala.collection.immutable.List.mapConserve(List.scala:472)
	at dotty.tools.dotc.core.classfile.ClassfileParser$$anon$2.apply(ClassfileParser.scala:47)
	at dotty.tools.dotc.core.classfile.ClassfileParser$AttributeCompleter.complete(ClassfileParser.scala:720)
	at dotty.tools.dotc.core.classfile.ClassfileParser.parseClass(ClassfileParser.scala:219)
	at dotty.tools.dotc.core.classfile.ClassfileParser.$anonfun$1(ClassfileParser.scala:87)
	at dotty.tools.dotc.core.classfile.ClassfileParser.run(ClassfileParser.scala:82)
	at dotty.tools.dotc.core.ClassfileLoader.load(SymbolLoaders.scala:411)
	at dotty.tools.dotc.core.ClassfileLoader.doComplete(SymbolLoaders.scala:406)
	at dotty.tools.dotc.core.SymbolLoader.complete(SymbolLoaders.scala:340)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:171)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeOnce(SymDenotations.scala:365)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.unforcedDecls(SymDenotations.scala:389)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.typeParamsFromDecls(SymDenotations.scala:1794)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.typeParams(SymDenotations.scala:1807)
	at dotty.tools.dotc.core.classfile.ClassfileParser$$anon$2.apply(ClassfileParser.scala:38)
	at dotty.tools.dotc.core.classfile.ClassfileParser$$anon$2.apply(ClassfileParser.scala:37)
	at scala.collection.immutable.List.mapConserve(List.scala:472)
	at dotty.tools.dotc.core.classfile.ClassfileParser$$anon$2.apply(ClassfileParser.scala:47)
	at dotty.tools.dotc.core.classfile.ClassfileParser$AttributeCompleter.complete(ClassfileParser.scala:720)
	at dotty.tools.dotc.core.classfile.ClassfileParser.parseClass(ClassfileParser.scala:219)
	at dotty.tools.dotc.core.classfile.ClassfileParser.$anonfun$1(ClassfileParser.scala:87)
	at dotty.tools.dotc.core.classfile.ClassfileParser.run(ClassfileParser.scala:82)
	at dotty.tools.dotc.core.ClassfileLoader.load(SymbolLoaders.scala:411)
	at dotty.tools.dotc.core.ClassfileLoader.doComplete(SymbolLoaders.scala:406)
	at dotty.tools.dotc.core.SymbolLoader.complete(SymbolLoaders.scala:340)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:171)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeOnce(SymDenotations.scala:365)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.unforcedDecls(SymDenotations.scala:389)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.typeParamsFromDecls(SymDenotations.scala:1794)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.typeParams(SymDenotations.scala:1807)
	at dotty.tools.dotc.core.classfile.ClassfileParser$$anon$2.apply(ClassfileParser.scala:38)
	at dotty.tools.dotc.core.classfile.ClassfileParser$$anon$2.apply(ClassfileParser.scala:37)
	at scala.collection.immutable.List.mapConserve(List.scala:472)
	at dotty.tools.dotc.core.classfile.ClassfileParser$$anon$2.apply(ClassfileParser.scala:47)
	at dotty.tools.dotc.core.classfile.ClassfileParser$AttributeCompleter.complete(ClassfileParser.scala:720)
	at dotty.tools.dotc.core.classfile.ClassfileParser.parseClass(ClassfileParser.scala:219)
	at dotty.tools.dotc.core.classfile.ClassfileParser.$anonfun$1(ClassfileParser.scala:87)
	at dotty.tools.dotc.core.classfile.ClassfileParser.run(ClassfileParser.scala:82)
	at dotty.tools.dotc.core.ClassfileLoader.load(SymbolLoaders.scala:411)
	at dotty.tools.dotc.core.ClassfileLoader.doComplete(SymbolLoaders.scala:406)
	at dotty.tools.dotc.core.SymbolLoader$$anon$1.doComplete(SymbolLoaders.scala:325)
	at dotty.tools.dotc.core.SymbolLoader.complete(SymbolLoaders.scala:340)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:171)
	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:373)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.flags(SymDenotations.scala:64)
	at dotty.tools.dotc.core.SymDenotations$ModuleCompleter.complete(SymDenotations.scala:2694)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:171)
	at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
	at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:373)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.flags(SymDenotations.scala:64)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.is(SymDenotations.scala:110)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.accessBoundary(SymDenotations.scala:1393)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.isPublic(SymDenotations.scala:1400)
	at scala.meta.internal.pc.CompilerSearchVisitor.isAccessible(CompilerSearchVisitor.scala:18)
	at scala.meta.internal.pc.CompilerSearchVisitor.$anonfun$1$$anonfun$3(CompilerSearchVisitor.scala:34)
	at scala.collection.immutable.List.filter(List.scala:515)
	at scala.meta.internal.pc.CompilerSearchVisitor.$anonfun$1(CompilerSearchVisitor.scala:34)
	at scala.collection.immutable.List.flatMap(List.scala:293)
	at scala.meta.internal.pc.CompilerSearchVisitor.loop$1(CompilerSearchVisitor.scala:34)
	at scala.meta.internal.pc.CompilerSearchVisitor.toSymbols(CompilerSearchVisitor.scala:40)
	at scala.meta.internal.pc.CompilerSearchVisitor.visitClassfile(CompilerSearchVisitor.scala:51)
	at scala.meta.internal.metals.ClasspathSearch.$anonfun$search$5(ClasspathSearch.scala:49)
	at scala.meta.internal.metals.ClasspathSearch.$anonfun$search$5$adapted(ClasspathSearch.scala:39)
	at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:575)
	at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:573)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1300)
	at scala.meta.internal.metals.ClasspathSearch.search(ClasspathSearch.scala:39)
	at scala.meta.internal.metals.WorkspaceSymbolProvider.search(WorkspaceSymbolProvider.scala:62)
	at scala.meta.internal.metals.MetalsSymbolSearch.search(MetalsSymbolSearch.scala:99)
	at scala.meta.internal.pc.completions.Completions.enrichWithSymbolSearch(Completions.scala:565)
	at scala.meta.internal.pc.completions.Completions.filterInteresting(Completions.scala:649)
	at scala.meta.internal.pc.completions.Completions.completions(Completions.scala:191)
	at scala.meta.internal.pc.completions.CompletionProvider.completions(CompletionProvider.scala:77)

Looks related to #2809

Expectation

No exception is thrown.

@tgodzik tgodzik added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 12, 2022
tgodzik added a commit to tgodzik/metals that referenced this issue Oct 12, 2022
It seems that it can sometimes throw an exception, which will make no completions show up for example in some scope completions in metals codebase.

Related to scala/scala3#16175
tgodzik added a commit to tgodzik/metals that referenced this issue Oct 12, 2022
It seems that it can sometimes throw an exception, which will make no completions show up for example in some scope completions in metals codebase.

Related to scala/scala3#16175
@Kordyjan Kordyjan added area:ide itype:crash and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 12, 2022
@dwijnand
Copy link
Member

It seems there is an issue with shaded scala collection classfiles inside coursierapi.

Yeah, there's where the bug is: the shading rewrote a bunch of fully qualified references in the bytecode, but not in the scala 2 pickle. I'm not sure how many "wait, but what if the pickle is wrong" checks we want to put in the scala 2 unpickler, as a workaround for broken shading.

Is it something we are doing or an issue with the compiler? Anyway I wouldn't expect isPublic method to throw an exception.

isPublic is just triggering things to run, that are only run lazily. It's the reality of lazy execution, which isn't common, so that can be unexpected.

@dwijnand dwijnand closed this as not planned Won't fix, can't repro, duplicate, stale Oct 12, 2022
@tgodzik
Copy link
Contributor Author

tgodzik commented Oct 12, 2022

Shouldn't we at least wrap that the problematic part in a try? It's not something we can sensibly handle on our own.

@tgodzik
Copy link
Contributor Author

tgodzik commented Oct 12, 2022

Also for:

//> using scala "3.2.0"
//> using lib "io.get-coursier:interface:1.0.9"


def main() =
    println("tree")
    import coursierapi.shaded.scala.collection.List
    List(123)

compilation fails. So currently it's not possible to use shaded libraries, which might be a legitimate restriction, but wanted to confirm.

@dwijnand
Copy link
Member

Do you mean wrap in the compiler? How do we handle it? What should isPublic return, assuming we can identify we're in a situation with broken pickles? false? Change its type to Try[Boolean]? I'm not sure if meta should handle it or if it should fall to metals.

So currently it's not possible to use shaded libraries, which might be a legitimate restriction, but wanted to confirm.

Sounds right to me.

@alexarchambault
Copy link
Contributor

alexarchambault commented Oct 12, 2022

coursier-interface uses jarjar-abrams, which should also process picking annotations. But maybe its picking annotation processing capabilities are too limited?

tgodzik added a commit to scalameta/metals that referenced this issue Oct 13, 2022
It seems that it can sometimes throw an exception, which will make no completions show up for example in some scope completions in metals codebase.

Related to scala/scala3#16175
tgodzik added a commit to tgodzik/metals that referenced this issue Aug 25, 2023
…sspath

We previously fixed another issue connected to this, when no completions would be available because `isPublic` would throw an exception. Now, it turns out we needed to wrap `toSymbols` methods, otherwise we would not get the duplicated symbols (which are also shadowed)

Connected to scala/scala3#16175
tgodzik added a commit to tgodzik/metals that referenced this issue Aug 25, 2023
…sspath

We previously fixed another issue connected to this, when no completions would be available because `isPublic` would throw an exception. Now, it turns out we needed to wrap `toSymbols` methods, otherwise we would not get the duplicated symbols (which are also shadowed)

Connected to scala/scala3#16175
tgodzik added a commit to tgodzik/metals that referenced this issue Aug 25, 2023
…sspath

We previously fixed another issue connected to this, when no completions would be available because `isPublic` would throw an exception. Now, it turns out we needed to wrap `toSymbols` methods, otherwise we would not get the duplicated symbols (which are also shadowed)

Connected to scala/scala3#16175
tgodzik added a commit to scalameta/metals that referenced this issue Aug 28, 2023
…sspath

We previously fixed another issue connected to this, when no completions would be available because `isPublic` would throw an exception. Now, it turns out we needed to wrap `toSymbols` methods, otherwise we would not get the duplicated symbols (which are also shadowed)

Connected to scala/scala3#16175
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

4 participants