Skip to content

Presumed mutation occurring in Symbol processing (paramSymss function) causes crashes #9240

Closed
@gzoller

Description

@gzoller

Minimized code

Please see minimal (2 file) project here: https://github.com/gzoller/dottybug1/tree/master/src

I am using Reflection to dive into a class and extract the type parameters of a class (AppliedType in my case). I get the primary constructor then the paramSymss like this:

symbol.primaryConstructor.paramSymss

You can see from my trivial project I can get quality output from this, as expected, on the first pass.
But...
If I turn around immediately and re-run the same function I get the error output below:

Output

=== Here in class HashSet
    Primary: method <init>
    Const: List(List(type A), List(val rootNode))
    Size: -1
    Nonempty? true
    Head: List(type A)
P: List(List(type A), List(val rootNode))
Syms : List(A)
=== Here in class HashSet
    Primary: method <init>
[error] -- Error: /Users/wmy965/git/dottybug/dottybug/src/main/scala/Main.scala:8:28 ---
[error] 8 |    println(LookSee.diveInto[scala.collection.immutable.HashSet[String]])
[error]   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]   |Exception occurred while executing macro expansion.
[error]   |java.util.NoSuchElementException: head of empty list
[error]   |	at scala.collection.immutable.Nil$.head(List.scala:629)
[error]   |	at scala.collection.immutable.Nil$.head(List.scala:628)
[error]   |	at dotty.tools.dotc.core.SymDenotations$SymDenotation.recurWithParamss$1(SymDenotations.scala:403)
[error]   |	at dotty.tools.dotc.core.SymDenotations$SymDenotation.recurWithParamss$1(SymDenotations.scala:403)
[error]   |	at dotty.tools.dotc.core.SymDenotations$SymDenotation.paramSymss(SymDenotations.scala:419)
[error]   |	at dotty.tools.dotc.tastyreflect.ReflectionCompilerInterface.Symbol_paramSymss(ReflectionCompilerInterface.scala:1771)
[error]   |	at dotty.tools.dotc.tastyreflect.ReflectionCompilerInterface.Symbol_paramSymss(ReflectionCompilerInterface.scala:1770)
[error]   |	at scala.tasty.Reflection$SymbolOps$.paramSymss(Reflection.scala:2275)
[error]   |	at com.boom.LookSee$.getTypeParameters(LookSee.scala:33)
[error]   |	at com.boom.LookSee$.unwindType(LookSee.scala:24)
[error]   |	at com.boom.LookSee$.diveIntoImpl(LookSee.scala:15)
[error]   |
[error]   | This location contains code that was inlined from Main.scala:8

Expectation

The way paramSymss is presented, I would expect it is a "getter" and should be re-callable as many times as you wish on the same symbol and get the same results. It appears that this function, or its tributaries, is mutating something such that re-calling the function causes the repeatable crash above.

I'm running 0.25.0-RC2 for this example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions