Skip to content

Commit 341244f

Browse files
committed
Prevent crashes in erroneous cases
1 parent 3f9d73f commit 341244f

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

+12-10
Original file line numberDiff line numberDiff line change
@@ -1715,16 +1715,18 @@ trait Applications extends Compatibility {
17151715
def typedUnApply(tree: untpd.UnApply, selType: Type)(using Context): UnApply =
17161716
throw new UnsupportedOperationException("cannot type check an UnApply node")
17171717

1718-
def typedAppliedConstructorType(tree: untpd.Apply)(using Context) =
1719-
val Select(New(tpt), _) = tree.fun: @unchecked // Always wrapped in `New`, see `simpleType` in `Parsers`
1720-
val tree1 = typedExpr(tree)
1721-
val widenSkolemsMap = new TypeMap:
1722-
def apply(tp: Type) = mapOver(tp.widenSkolem)
1723-
val preciseTp = widenSkolemsMap(tree1.tpe)
1724-
val classTp = typedType(tpt).tpe
1725-
if !preciseTp.isError && (preciseTp frozen_=:= classTp) then
1726-
report.warning(PointlessAppliedConstructorType(tpt, tree.args, classTp), tree.srcPos)
1727-
TypeTree(preciseTp)
1718+
def typedAppliedConstructorType(tree: untpd.Apply)(using Context) = tree.fun match
1719+
case Select(New(tpt), _) =>
1720+
val tree1 = typedExpr(tree)
1721+
val widenSkolemsMap = new TypeMap:
1722+
def apply(tp: Type) = mapOver(tp.widenSkolem)
1723+
val preciseTp = widenSkolemsMap(tree1.tpe)
1724+
val classTp = typedType(tpt).tpe
1725+
if !preciseTp.isError && (preciseTp frozen_=:= classTp) then
1726+
report.warning(PointlessAppliedConstructorType(tpt, tree.args, classTp), tree.srcPos)
1727+
TypeTree(preciseTp)
1728+
case _ =>
1729+
throw TypeError(em"Unexpected applied constructor type: $tree")
17281730

17291731
/** Is given method reference applicable to argument trees `args`?
17301732
* @param resultType The expected result type of the application

tests/neg/context-function-syntax.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
val test =
2-
(using x: Int) => x // error // error
2+
(using x: Int) => x // error // error // error
33

44
val f = () ?=> 23 // error
55
val g: ContextFunction0[Int] = ??? // ok

tests/neg/deptypes.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
type Vec[T] = (n: Int) =>> Array[T] // error: not yet implemented
44

5-
type Matrix[T](m: Int, n: Int) = Vec[Vec[T](n)](m) // error: not yet implemented
5+
type Matrix[T](m: Int, n: Int) = Vec[Vec[T](n)](m) // error // error: not yet implemented
66

7-
type Tensor2[T](m: Int)(n: Int) = Matrix[T](m, n) // error: not yet implemented
7+
type Tensor2[T](m: Int)(n: Int) = Matrix[T](m, n)
88

9-
val x: Vec[Int](10) = ??? // error: not yet implemented
9+
val x: Vec[Int](10) = ???
1010
val n = 10
11-
type T = Vec[String](n) // error: not yet implemented
11+
type T = Vec[String](n)

tests/neg/i7751.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import language.`3.3`
2-
val a = Some(a=a,)=> // error // error // error // error
2+
val a = Some(a=a,)=> // error // error // error
33
val a = Some(x=y,)=>

0 commit comments

Comments
 (0)