Skip to content

More tweaks to harden IDE #2838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,16 @@ trait ConstraintHandling {
}
}
}
assert(constraint.contains(param))
val bound = if (fromBelow) constraint.fullLowerBound(param) else constraint.fullUpperBound(param)
val inst = avoidParam(bound)
typr.println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}")
inst
if (constraint.contains(param)) {
val bound = if (fromBelow) constraint.fullLowerBound(param) else constraint.fullUpperBound(param)
val inst = avoidParam(bound)
typr.println(s"approx ${param.show}, from below = $fromBelow, bound = ${bound.show}, inst = ${inst.show}")
inst
}
else {
assert(ctx.mode.is(Mode.Interactive))
UnspecifiedErrorType
}
}

/** The instance type of `param` in the current constraint (which contains `param`).
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3194,7 +3194,6 @@ object Types {
private def instantiateWith(tp: Type)(implicit ctx: Context): Type = {
assert(tp ne this, s"self instantiation of ${tp.show}, constraint = ${ctx.typerState.constraint.show}")
typr.println(s"instantiating ${this.show} with ${tp.show}")
assert(ctx.typerState.constraint contains this) // !!! DEBUG
if ((ctx.typerState eq owningState) && !ctx.typeComparer.subtypeCheckInProgress)
inst = tp
ctx.typerState.constraint = ctx.typerState.constraint.replace(origin, tp)
Expand Down
10 changes: 7 additions & 3 deletions compiler/src/dotty/tools/dotc/interactive/Interactive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ object Interactive {
/** Possible completions of members of `prefix` which are accessible when called inside `boundary` */
def completions(prefix: Type, boundary: Symbol)(implicit ctx: Context): List[Symbol] = {
val boundaryCtx = ctx.withOwner(boundary)
prefix.memberDenots(completionsFilter, (name, buf) =>
buf ++= prefix.member(name).altsWith(_.symbol.isAccessibleFrom(prefix)(boundaryCtx))
).map(_.symbol).toList
try
prefix.memberDenots(completionsFilter, (name, buf) =>
buf ++= prefix.member(name).altsWith(_.symbol.isAccessibleFrom(prefix)(boundaryCtx))
).map(_.symbol).toList
catch {
case ex: TypeError => Nil
}
}

/** Filter for names that should appear when looking for completions. */
Expand Down
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,12 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
else if (cx.scope != cx.outer.scope &&
cx.denotNamed(meth.name).hasAltWith(_.symbol == meth)) {
val denot = cx.denotNamed(getterName)
assert(denot.exists, s"non-existent getter denotation ($denot) for getter($getterName)")
ref(TermRef(cx.owner.thisType, getterName, denot))
if (denot.exists) ref(TermRef(cx.owner.thisType, getterName, denot))
else {
assert(ctx.mode.is(Mode.Interactive),
s"non-existent getter denotation ($denot) for getter($getterName)")
findGetter(cx.outer)
}
} else findGetter(cx.outer)
}
findGetter(ctx)
Expand Down
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
def caseRest(pat: Tree)(implicit ctx: Context) = {
val pat1 = indexPattern.transform(pat)
val guard1 = typedExpr(tree.guard, defn.BooleanType)
val body1 = ensureNoLocalRefs(typedExpr(tree.body, pt), pt, ctx.scope.toList)
.ensureConforms(pt)(originalCtx) // insert a cast if body does not conform to expected type if we disregard gadt bounds
var body1 = ensureNoLocalRefs(typedExpr(tree.body, pt), pt, ctx.scope.toList)
if (pt.isValueType) // insert a cast if body does not conform to expected type if we disregard gadt bounds
body1 = body1.ensureConforms(pt)(originalCtx)
assignType(cpy.CaseDef(tree)(pat1, guard1, body1), body1)
}

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