Skip to content

Fix #7149: Revert inference change #7161

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 3 commits into from
Sep 3, 2019
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
33 changes: 15 additions & 18 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -653,14 +653,16 @@ object Parsers {
lineStart
}

val needsBraces = t match {
case Block(Nil, expr) =>
def needsBraces(t: Any): Boolean = t match {
case Block(stats, expr) =>
stats.nonEmpty || needsBraces(expr)
case expr: Tree =>
followsColon ||
isPartialIf(expr) && in.token == ELSE ||
isBlockFunction(expr)
case _ => true
}
if (needsBraces) {
if (needsBraces(t)) {
patch(source, Span(startOpening, endOpening), " {")
patch(source, Span(closingOffset(source.nextLine(in.lastOffset))), indentWidth.toPrefix ++ "}\n")
}
Expand Down Expand Up @@ -1361,11 +1363,7 @@ object Parsers {
else t

/** The block in a quote or splice */
def stagedBlock() =
inDefScopeBraces(block()) match {
case t @ Block(Nil, expr) if !expr.isEmpty => expr
case t => t
}
def stagedBlock() = inDefScopeBraces(block(simplify = true))

/** SimpleEpxr ::= spliceId | ‘$’ ‘{’ Block ‘}’)
* SimpleType ::= spliceId | ‘$’ ‘{’ Block ‘}’)
Expand Down Expand Up @@ -2148,27 +2146,26 @@ object Parsers {
* BlockExprContents ::= CaseClauses | Block
*/
def blockExpr(): Tree = atSpan(in.offset) {
val simplify = in.token == INDENT
inDefScopeBraces {
if (in.token == CASE) Match(EmptyTree, caseClauses(caseClause))
else block()
else block(simplify)
}
}

/** Block ::= BlockStatSeq
* @note Return tree does not have a defined span.
*/
def block(): Tree = {
def block(simplify: Boolean = false): Tree = {
val stats = blockStatSeq()
def isExpr(stat: Tree) = !(stat.isDef || stat.isInstanceOf[Import])
stats match {
case (stat : Block) :: Nil =>
stat // A typical case where this happens is creating a block around a region
// hat is already indented, e.g. something following a =>.
case _ :: stats1 if isExpr(stats.last) =>
Block(stats.init, stats.last)
case _ =>
Block(stats, EmptyTree)
if (stats.nonEmpty && isExpr(stats.last)) {
val inits = stats.init
val last = stats.last
if (inits.isEmpty && (simplify || last.isInstanceOf[Block])) last
else Block(inits, last)
}
else Block(stats, EmptyTree)
}

/** Guard ::= if PostfixExpr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
val isExtension = tree.hasType && tree.symbol.is(Extension)
withEnclosingDef(tree) {
val (prefix, vparamss) =
if(isExtension) (defKeyword ~~ paramsText(tree.vparamss.head) ~~ valDefText(nameIdText(tree)), tree.vparamss.tail)
if (isExtension) (defKeyword ~~ paramsText(tree.vparamss.head) ~~ valDefText(nameIdText(tree)), tree.vparamss.tail)
else (defKeyword ~~ valDefText(nameIdText(tree)), tree.vparamss)

addVparamssText(prefix ~ tparamsText(tree.tparams), vparamss) ~
Expand Down
9 changes: 1 addition & 8 deletions compiler/src/dotty/tools/dotc/typer/Inferencing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,7 @@ trait Inferencing { this: Typer =>
else if (!hasUnreportedErrors)
if (v.intValue != 0) {
typr.println(i"interpolate $tvar in $state in $tree: $tp, fromBelow = ${v.intValue == 1}, $constraint")
if (true) {
val fromBelow = v.intValue == 1
val instType = ctx.typeComparer.instanceType(tvar.origin, fromBelow)
if (!(fromBelow && instType.isRef(defn.NothingClass)))
tvar.instantiateWith(instType)
}
else
tvar.instantiate(fromBelow = v.intValue == 1)
tvar.instantiate(fromBelow = v.intValue == 1)
}
else typr.println(i"no interpolation for nonvariant $tvar in $state")
}
Expand Down
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions tests/pos/i7149.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
trait ZIO[-R, +E, +A] { self =>

final def +++[R1, B, E1 >: E](that: ZIO[R1, E1, B]): ZIO[Either[R, R1], E1, Either[A, B]] =
for {
e <- ZIO.environment[Either[R, R1]]
r <- e.fold(self.map(Left(_)) provide _, that.map(Right(_)) provide _)
} yield r
// Found: (Left[A, Any] | Right[Any, B])(r)
// Required: Either[A, B]

def flatMap[R1 <: R, E1 >: E, B](f: A => ZIO[R1, E1, B]): ZIO[R1, E1, B] = ???

def map[B](f: A => B): ZIO[R, E, B] = ???

def provide[R](R: R): ZIO[Any, E, A] = ???
}

object ZIO {
def environment[R]: ZIO[R, Nothing, R] = ???
}
3 changes: 1 addition & 2 deletions tests/run/type-propagation.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
object Test extends App {
def foo: String = {
def foo: String =
"abc".asInstanceOf
}

assert(foo == "abc")
}