Skip to content

Commit eccdc2f

Browse files
paulpretronym
authored andcommitted
Fix for rangepos crasher.
wrapClassTagUnapply was generating an unpositioned tree which would crash under -Yrangepos. See SI-6338.
1 parent 70a24f9 commit eccdc2f

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3362,12 +3362,13 @@ trait Typers extends Modes with Adaptations with Tags {
33623362
// println(util.Position.formatMessage(uncheckedPattern.pos, "made unchecked type test into a checked one", true))
33633363

33643364
val args = List(uncheckedPattern)
3365+
val app = atPos(uncheckedPattern.pos)(Apply(classTagExtractor, args))
33653366
// must call doTypedUnapply directly, as otherwise we get undesirable rewrites
33663367
// and re-typechecks of the target of the unapply call in PATTERNmode,
33673368
// this breaks down when the classTagExtractor (which defineds the unapply member) is not a simple reference to an object,
33683369
// but an arbitrary tree as is the case here
3369-
doTypedUnapply(Apply(classTagExtractor, args), classTagExtractor, classTagExtractor, args, PATTERNmode, pt)
3370-
}
3370+
doTypedUnapply(app, classTagExtractor, classTagExtractor, args, PATTERNmode, pt)
3371+
}
33713372

33723373
// if there's a ClassTag that allows us to turn the unchecked type test for `pt` into a checked type test
33733374
// return the corresponding extractor (an instance of ClassTag[`pt`])

test/files/pos/classtag-pos.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Yrangepos

test/files/pos/classtag-pos.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import scala.reflect.runtime.universe._
2+
3+
class A {
4+
def f[T: TypeTag] = typeOf[T] match { case TypeRef(_, _, args) => args }
5+
}

0 commit comments

Comments
 (0)