Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Aug 9, 2024
1 parent cc7374d commit ca93d63
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ trait Applications extends Compatibility {
def makeVarArg(n: Int, elemFormal: Type): Unit = {
val args = typedArgBuf.takeRight(n).toList
typedArgBuf.dropRightInPlace(n)
val elemtpt = TypeTree(elemFormal)
val elemtpt = TypeTree(if !args.exists(_.tpe.isError) then elemFormal else UnspecifiedErrorType)
typedArgBuf += seqToRepeated(SeqLiteral(args, elemtpt))
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ trait TypeAssigner {
else tree.withType(TypeComparer.lub(expr.tpe :: cases.tpes))

def assignType(tree: untpd.SeqLiteral, elems: List[Tree], elemtpt: Tree)(using Context): SeqLiteral =
tree.withType(seqLitType(tree, elemtpt.tpe))
tree.withType(if elemtpt.tpe.isError then elemtpt.tpe else seqLitType(tree, elemtpt.tpe))

def assignType(tree: untpd.SingletonTypeTree, ref: Tree)(using Context): SingletonTypeTree =
tree.withType(ref.tpe)
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3535,6 +3535,10 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
if !tree.tpe.widen.isInstanceOf[MethodOrPoly] // wait with simplifying until method is fully applied
|| tree.isDef // ... unless tree is a definition
then
//val tvars = (ctx.typerState.ownedVars -- locked).toList
//val forceDegree = new ForceDegree.Value(IfBottom.fail) { override def appliesTo(tvar: TypeVar) = tvars.contains(tvar) }
//isFullyDefined(tree.tpe, forceDegree)
//isFullyDefined(tree.tpe, ForceDegree.failBottom)
interpolateTypeVars(tree, pt, locked)
val simplified = tree.tpe.simplified
if !MatchType.thatReducesUsingGadt(tree.tpe) then // needs a GADT cast. i15743
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import dotty.tools.dotc.core.Types.*
import dotty.tools.dotc.core.Types.Type
import dotty.tools.dotc.interactive.Interactive
import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.dotc.typer.Applications.UnapplyArgs
import dotty.tools.dotc.util.NoSourcePosition
import dotty.tools.dotc.util.SourceFile
import dotty.tools.dotc.util.Spans.Span
import dotty.tools.pc.IndexedContext
Expand Down Expand Up @@ -86,9 +88,15 @@ object InterCompletionType:
// List(@@)
case SeqLiteral(_, tpe) :: _ if !tpe.tpe.isErroneous =>
Some(tpe.tpe)
case SeqLiteral(_, _) :: _typed :: rest =>
inferType(rest, span)
// val _: T = @@
// def _: T = @@
case (defn: ValOrDefDef) :: rest if !defn.tpt.tpe.isErroneous => Some(defn.tpt.tpe)
case UnApply(fun, _, pats) :: _ =>
val ind = pats.indexWhere(_.span.contains(span))
if ind < 0 then None
else Some(UnapplyArgs(fun.tpe.finalResultType, fun, pats, NoSourcePosition).argTypes(ind))
// f(@@)
case (app: Apply) :: rest =>
val param =
Expand All @@ -98,7 +106,7 @@ object InterCompletionType:
}
params <- app.symbol.paramSymss.find(!_.exists(_.isTypeParam))
param <- params.get(ind)
} yield param.info
} yield param.info.repeatedToSingle
param match
// def f[T](a: T): T = ???
// f[Int](@@)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class InferExpectedTypeSuite extends BasePCSuite:
|""".stripMargin
)

@Ignore("Not handled correctly.")
@Test def list =
check(
"""|val i: List[Int] = List(@@)
Expand Down Expand Up @@ -193,7 +192,6 @@ class InferExpectedTypeSuite extends BasePCSuite:
|""".stripMargin
)

@Ignore("Unapply is not handled correctly.")
@Test def unapply =
check(
"""|val _ =
Expand Down Expand Up @@ -223,62 +221,60 @@ class InferExpectedTypeSuite extends BasePCSuite:
|""".stripMargin
)

@Ignore("Generic functions are not handled correctly.")
@Test def flatmap =
check(
"""|val _ : List[Int] = List().flatMap(_ => @@)
|""".stripMargin,
"""|IterableOnce[Int]
"""|IterableOnce[Nothing]
|""".stripMargin
// IterableOnce[Int]
// requires changing interpolateTypeVars
)

@Ignore("Generic functions are not handled correctly.")
@Test def `for-comprehension` =
check(
"""|val _ : List[Int] =
| for {
| _ <- List("a", "b")
| } yield @@
|""".stripMargin,
"""|Int
"""|Nothing
|""".stripMargin
// Int
// requires changing interpolateTypeVars
)

// bounds
@Ignore("Bounds are not handled correctly.")
@Test def any =
check(
"""|trait Foo
|def foo[T](a: T): Boolean = ???
|val _ = foo(@@)
|""".stripMargin,
"""|<: Any
"""|Any
|""".stripMargin
)

@Ignore("Bounds are not handled correctly.")
@Test def `bounds-1` =
check(
"""|trait Foo
|def foo[T <: Foo](a: Foo): Boolean = ???
|def foo[T <: Foo](a: T): Boolean = ???
|val _ = foo(@@)
|""".stripMargin,
"""|<: Foo
"""|Foo
|""".stripMargin
)

@Ignore("Bounds are not handled correctly.")
@Test def `bounds-2` =
check(
"""|trait Foo
|def foo[T :> Foo](a: Foo): Boolean = ???
|def foo[T :> Foo](a: T): Boolean = ???
|val _ = foo(@@)
|""".stripMargin,
"""|:> Foo
"""|Any
|""".stripMargin
)

@Ignore("Bounds are not handled correctly.")
@Test def `bounds-3` =
check(
"""|trait A
Expand All @@ -287,6 +283,6 @@ class InferExpectedTypeSuite extends BasePCSuite:
|def roo[F >: C <: A](f: F) = ???
|val kjk = roo(@@)
|""".stripMargin,
"""|>: C <: A
"""|C
|""".stripMargin
)

0 comments on commit ca93d63

Please sign in to comment.