Skip to content

Commit

Permalink
Prevent crashes in erroneous cases
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperFKorban committed Feb 6, 2025
1 parent 42df82b commit a12b589
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
22 changes: 12 additions & 10 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1694,16 +1694,18 @@ trait Applications extends Compatibility {
def typedUnApply(tree: untpd.UnApply, selType: Type)(using Context): UnApply =
throw new UnsupportedOperationException("cannot type check an UnApply node")

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

/** Is given method reference applicable to argument trees `args`?
* @param resultType The expected result type of the application
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/context-function-syntax.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
val test =
(using x: Int) => x // error // error
(using x: Int) => x // error // error // error

val f = () ?=> 23 // error
val g: ContextFunction0[Int] = ??? // ok
Expand Down
8 changes: 4 additions & 4 deletions tests/neg/deptypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

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

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

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

val x: Vec[Int](10) = ??? // error: not yet implemented
val x: Vec[Int](10) = ???
val n = 10
type T = Vec[String](n) // error: not yet implemented
type T = Vec[String](n)
2 changes: 1 addition & 1 deletion tests/neg/i7751.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import language.`3.3`
val a = Some(a=a,)=> // error // error // error // error
val a = Some(a=a,)=> // error // error // error
val a = Some(x=y,)=>

0 comments on commit a12b589

Please sign in to comment.