Skip to content

Commit a9b7beb

Browse files
authored
Merge pull request #2838 from dotty-staging/harden-ide
More tweaks to harden IDE
2 parents dd517c5 + 7c379ce commit a9b7beb

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala

+10-5
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,16 @@ trait ConstraintHandling {
222222
}
223223
}
224224
}
225-
assert(constraint.contains(param))
226-
val bound = if (fromBelow) constraint.fullLowerBound(param) else constraint.fullUpperBound(param)
227-
val inst = avoidParam(bound)
228-
typr.println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}")
229-
inst
225+
if (constraint.contains(param)) {
226+
val bound = if (fromBelow) constraint.fullLowerBound(param) else constraint.fullUpperBound(param)
227+
val inst = avoidParam(bound)
228+
typr.println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}")
229+
inst
230+
}
231+
else {
232+
assert(ctx.mode.is(Mode.Interactive))
233+
UnspecifiedErrorType
234+
}
230235
}
231236

232237
/** The instance type of `param` in the current constraint (which contains `param`).

compiler/src/dotty/tools/dotc/core/Types.scala

-1
Original file line numberDiff line numberDiff line change
@@ -3194,7 +3194,6 @@ object Types {
31943194
private def instantiateWith(tp: Type)(implicit ctx: Context): Type = {
31953195
assert(tp ne this, s"self instantiation of ${tp.show}, constraint = ${ctx.typerState.constraint.show}")
31963196
typr.println(s"instantiating ${this.show} with ${tp.show}")
3197-
assert(ctx.typerState.constraint contains this) // !!! DEBUG
31983197
if ((ctx.typerState eq owningState) && !ctx.typeComparer.subtypeCheckInProgress)
31993198
inst = tp
32003199
ctx.typerState.constraint = ctx.typerState.constraint.replace(origin, tp)

compiler/src/dotty/tools/dotc/interactive/Interactive.scala

+7-3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,13 @@ object Interactive {
8787
/** Possible completions of members of `prefix` which are accessible when called inside `boundary` */
8888
def completions(prefix: Type, boundary: Symbol)(implicit ctx: Context): List[Symbol] = {
8989
val boundaryCtx = ctx.withOwner(boundary)
90-
prefix.memberDenots(completionsFilter, (name, buf) =>
91-
buf ++= prefix.member(name).altsWith(_.symbol.isAccessibleFrom(prefix)(boundaryCtx))
92-
).map(_.symbol).toList
90+
try
91+
prefix.memberDenots(completionsFilter, (name, buf) =>
92+
buf ++= prefix.member(name).altsWith(_.symbol.isAccessibleFrom(prefix)(boundaryCtx))
93+
).map(_.symbol).toList
94+
catch {
95+
case ex: TypeError => Nil
96+
}
9397
}
9498

9599
/** Filter for names that should appear when looking for completions. */

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,12 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
366366
else if (cx.scope != cx.outer.scope &&
367367
cx.denotNamed(meth.name).hasAltWith(_.symbol == meth)) {
368368
val denot = cx.denotNamed(getterName)
369-
assert(denot.exists, s"non-existent getter denotation ($denot) for getter($getterName)")
370-
ref(TermRef(cx.owner.thisType, getterName, denot))
369+
if (denot.exists) ref(TermRef(cx.owner.thisType, getterName, denot))
370+
else {
371+
assert(ctx.mode.is(Mode.Interactive),
372+
s"non-existent getter denotation ($denot) for getter($getterName)")
373+
findGetter(cx.outer)
374+
}
371375
} else findGetter(cx.outer)
372376
}
373377
findGetter(ctx)

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -940,8 +940,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
940940
def caseRest(pat: Tree)(implicit ctx: Context) = {
941941
val pat1 = indexPattern.transform(pat)
942942
val guard1 = typedExpr(tree.guard, defn.BooleanType)
943-
val body1 = ensureNoLocalRefs(typedExpr(tree.body, pt), pt, ctx.scope.toList)
944-
.ensureConforms(pt)(originalCtx) // insert a cast if body does not conform to expected type if we disregard gadt bounds
943+
var body1 = ensureNoLocalRefs(typedExpr(tree.body, pt), pt, ctx.scope.toList)
944+
if (pt.isValueType) // insert a cast if body does not conform to expected type if we disregard gadt bounds
945+
body1 = body1.ensureConforms(pt)(originalCtx)
945946
assignType(cpy.CaseDef(tree)(pat1, guard1, body1), body1)
946947
}
947948

@@ -1183,7 +1184,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
11831184
val pt1 = fullyDefinedType(pt, "pattern variable", tree.pos)
11841185
val body1 = typed(tree.body, pt1)
11851186
body1 match {
1186-
case UnApply(fn, Nil, arg :: Nil) if fn.symbol.owner == defn.ClassTagClass && !body1.tpe.isError =>
1187+
case UnApply(fn, Nil, arg :: Nil)
1188+
if fn.symbol.exists && fn.symbol.owner == defn.ClassTagClass && !body1.tpe.isError =>
11871189
// A typed pattern `x @ (e: T)` with an implicit `ctag: ClassTag[T]`
11881190
// was rewritten to `x @ ctag(e)` by `tryWithClassTag`.
11891191
// Rewrite further to `ctag(x @ e)`

0 commit comments

Comments
 (0)