Skip to content

Commit 9c0f0fc

Browse files
committed
Prevent crashes in erroneous cases
1 parent b301e48 commit 9c0f0fc

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
@@ -1694,16 +1694,18 @@ trait Applications extends Compatibility {
16941694
def typedUnApply(tree: untpd.UnApply, selType: Type)(using Context): UnApply =
16951695
throw new UnsupportedOperationException("cannot type check an UnApply node")
16961696

1697-
def typedAppliedConstructorType(tree: untpd.Apply)(using Context) =
1698-
val Select(New(tpt), _) = tree.fun: @unchecked // Always wrapped in `New`, see `simpleType` in `Parsers`
1699-
val tree1 = typedExpr(tree)
1700-
val widenSkolemsMap = new TypeMap:
1701-
def apply(tp: Type) = mapOver(tp.widenSkolem)
1702-
val preciseTp = widenSkolemsMap(tree1.tpe)
1703-
val classTp = typedType(tpt).tpe
1704-
if !preciseTp.isError && (preciseTp frozen_=:= classTp) then
1705-
report.warning(PointlessAppliedConstructorType(tpt, tree.args, classTp), tree.srcPos)
1706-
TypeTree(preciseTp)
1697+
def typedAppliedConstructorType(tree: untpd.Apply)(using Context) = tree.fun match
1698+
case Select(New(tpt), _) =>
1699+
val tree1 = typedExpr(tree)
1700+
val widenSkolemsMap = new TypeMap:
1701+
def apply(tp: Type) = mapOver(tp.widenSkolem)
1702+
val preciseTp = widenSkolemsMap(tree1.tpe)
1703+
val classTp = typedType(tpt).tpe
1704+
if !preciseTp.isError && (preciseTp frozen_=:= classTp) then
1705+
report.warning(PointlessAppliedConstructorType(tpt, tree.args, classTp), tree.srcPos)
1706+
TypeTree(preciseTp)
1707+
case _ =>
1708+
throw TypeError(em"Unexpected applied constructor type: $tree")
17071709

17081710
/** Is given method reference applicable to argument trees `args`?
17091711
* @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)