Skip to content

Commit

Permalink
Fix crash in footprint computation
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed Aug 23, 2024
1 parent 0bd084b commit dad0a95
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/init/Objects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,10 @@ class Objects(using Context @constructorOnly):
if !visited.contains(value) then
toVisit += value

case objRef: ObjectRef =>
// Thanks to initialization-time irrelevance, there is no need to
// visit the heap regions owned by other global objects.

case value: Value =>
recur(value)

Expand Down
26 changes: 26 additions & 0 deletions tests/init-global/pos/sconfig-array.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.{lang => jl}

final class ConfigValueType private (val name: String, val ordinal: Int)

object ConfigValueType:
final val OBJECT = new ConfigValueType("OBJECT", 0)
final val LIST = new ConfigValueType("LIST", 1)
final val NUMBER = new ConfigValueType("NUMBER", 2)
final val BOOLEAN = new ConfigValueType("BOOLEAN", 3)
final val NULL = new ConfigValueType("NULL", 4)
final val STRING = new ConfigValueType("STRING", 5)

final val _values: Array[ConfigValueType] =
Array(OBJECT, LIST, NUMBER, BOOLEAN, NULL, STRING)

def values: Array[ConfigValueType] = _values.clone()

def valueOf(name: String): ConfigValueType =
_values.find(_.name == name).getOrElse {
throw new IllegalArgumentException(
"No enum const ConfigValueType." + name
)
}

object Usage:
val c = ConfigValueType.valueOf("LIST")

0 comments on commit dad0a95

Please sign in to comment.