Skip to content

Span error caused by invalid match syntax #23729

@kyouko-taiga

Description

@kyouko-taiga

Compiler version

Scala compiler version 3.6.4 -- Copyright 2002-2025, LAMP/EPFL

Minimized code

trait Collection[Self, Element]:
  type Index
  extension (self: Self)
    def start: Index

sealed trait Tree[+T]
object Tree:
  case object Empty extends Tree[Nothing]
  case class Node[+T](value: T, lhs: Tree[T], rhs: Tree[T]) extends Tree[T]

enum Direction:
  case Left, Right, Here

given [T]: Collection[Tree[T], T] with
  type Index = List[Direction]
  extension (self: Tree[T])
    def start: List[Direction] = match self
      case Empty => Nil
      case Node(_, l, _) => l.start :+ Left

Output

Exception in thread "main" java.lang.AssertionError: assertion failed: position error, parent span does not contain child span
parent      = [T] extends Collection[Tree[T], T] {
  type Index = List[Direction]
  extension (self: Tree[T])
    {
      def start: List[Direction] = _root_.scala.Predef.???
      def <error> = _root_.scala.Predef.???
      def <error> = _root_.scala.Predef.???
    }
} # -1,
parent span = <1682..1884>,
child       = extension (self: Tree[T])
  {
    def start: List[Direction] = _root_.scala.Predef.???
    def <error> = _root_.scala.Predef.???
    def <error> = _root_.scala.Predef.???
  } # -1,
child span  = [1747..2046]
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
	at dotty.tools.dotc.ast.Positioned.check$1(Positioned.scala:177)
	at dotty.tools.dotc.ast.Positioned.check$1$$anonfun$3(Positioned.scala:207)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:334)
	at dotty.tools.dotc.ast.Positioned.check$1(Positioned.scala:207)
	at dotty.tools.dotc.ast.Positioned.checkPos(Positioned.scala:228)
	at dotty.tools.dotc.ast.Positioned.check$1(Positioned.scala:202)
	at dotty.tools.dotc.ast.Positioned.checkPos(Positioned.scala:228)
	at dotty.tools.dotc.ast.Positioned.check$1(Positioned.scala:202)
	at dotty.tools.dotc.ast.Positioned.check$1$$anonfun$3(Positioned.scala:207)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:334)
	at dotty.tools.dotc.ast.Positioned.check$1(Positioned.scala:207)
	at dotty.tools.dotc.ast.Positioned.checkPos(Positioned.scala:228)
	at dotty.tools.dotc.parsing.Parser.parse$$anonfun$1(ParserPhase.scala:39)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:510)
	at dotty.tools.dotc.parsing.Parser.parse(ParserPhase.scala:40)
	at dotty.tools.dotc.parsing.Parser.$anonfun$2(ParserPhase.scala:52)
	at scala.collection.Iterator$$anon$6.hasNext(Iterator.scala:479)
	at scala.collection.Iterator$$anon$9.hasNext(Iterator.scala:583)
	at scala.collection.immutable.List.prependedAll(List.scala:152)
	at scala.collection.immutable.List$.from(List.scala:685)
	at scala.collection.immutable.List$.from(List.scala:682)
	at scala.collection.IterableOps$WithFilter.map(Iterable.scala:900)
	at dotty.tools.dotc.parsing.Parser.runOn(ParserPhase.scala:51)
	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:343)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at dotty.tools.dotc.Run.runPhases$1(Run.scala:336)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:383)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:395)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:395)
	at dotty.tools.dotc.Run.compileSources(Run.scala:282)
	at dotty.tools.dotc.Run.compile(Run.scala:267)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
	at dotty.tools.dotc.Driver.process(Driver.scala:201)
	at dotty.tools.dotc.Driver.process(Driver.scala:169)
	at dotty.tools.dotc.Driver.process(Driver.scala:181)
	at dotty.tools.dotc.Driver.main(Driver.scala:211)
	at dotty.tools.dotc.Main.main(Main.scala)
Compilation failed

Expectation

Compiler should not crash.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions