Skip to content

Commit 85962b1

Browse files
authored
Merge pull request #7161 from dotty-staging/fix-#7149
Fix #7149: Revert inference change
2 parents d36e458 + 1b17ba2 commit 85962b1

File tree

8 files changed

+39
-30
lines changed

8 files changed

+39
-30
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -653,14 +653,16 @@ object Parsers {
653653
lineStart
654654
}
655655

656-
val needsBraces = t match {
657-
case Block(Nil, expr) =>
656+
def needsBraces(t: Any): Boolean = t match {
657+
case Block(stats, expr) =>
658+
stats.nonEmpty || needsBraces(expr)
659+
case expr: Tree =>
658660
followsColon ||
659661
isPartialIf(expr) && in.token == ELSE ||
660662
isBlockFunction(expr)
661663
case _ => true
662664
}
663-
if (needsBraces) {
665+
if (needsBraces(t)) {
664666
patch(source, Span(startOpening, endOpening), " {")
665667
patch(source, Span(closingOffset(source.nextLine(in.lastOffset))), indentWidth.toPrefix ++ "}\n")
666668
}
@@ -1361,11 +1363,7 @@ object Parsers {
13611363
else t
13621364

13631365
/** The block in a quote or splice */
1364-
def stagedBlock() =
1365-
inDefScopeBraces(block()) match {
1366-
case t @ Block(Nil, expr) if !expr.isEmpty => expr
1367-
case t => t
1368-
}
1366+
def stagedBlock() = inDefScopeBraces(block(simplify = true))
13691367

13701368
/** SimpleEpxr ::= spliceId | ‘$’ ‘{’ Block ‘}’)
13711369
* SimpleType ::= spliceId | ‘$’ ‘{’ Block ‘}’)
@@ -2148,27 +2146,26 @@ object Parsers {
21482146
* BlockExprContents ::= CaseClauses | Block
21492147
*/
21502148
def blockExpr(): Tree = atSpan(in.offset) {
2149+
val simplify = in.token == INDENT
21512150
inDefScopeBraces {
21522151
if (in.token == CASE) Match(EmptyTree, caseClauses(caseClause))
2153-
else block()
2152+
else block(simplify)
21542153
}
21552154
}
21562155

21572156
/** Block ::= BlockStatSeq
21582157
* @note Return tree does not have a defined span.
21592158
*/
2160-
def block(): Tree = {
2159+
def block(simplify: Boolean = false): Tree = {
21612160
val stats = blockStatSeq()
21622161
def isExpr(stat: Tree) = !(stat.isDef || stat.isInstanceOf[Import])
2163-
stats match {
2164-
case (stat : Block) :: Nil =>
2165-
stat // A typical case where this happens is creating a block around a region
2166-
// hat is already indented, e.g. something following a =>.
2167-
case _ :: stats1 if isExpr(stats.last) =>
2168-
Block(stats.init, stats.last)
2169-
case _ =>
2170-
Block(stats, EmptyTree)
2162+
if (stats.nonEmpty && isExpr(stats.last)) {
2163+
val inits = stats.init
2164+
val last = stats.last
2165+
if (inits.isEmpty && (simplify || last.isInstanceOf[Block])) last
2166+
else Block(inits, last)
21712167
}
2168+
else Block(stats, EmptyTree)
21722169
}
21732170

21742171
/** Guard ::= if PostfixExpr

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
766766
val isExtension = tree.hasType && tree.symbol.is(Extension)
767767
withEnclosingDef(tree) {
768768
val (prefix, vparamss) =
769-
if(isExtension) (defKeyword ~~ paramsText(tree.vparamss.head) ~~ valDefText(nameIdText(tree)), tree.vparamss.tail)
769+
if (isExtension) (defKeyword ~~ paramsText(tree.vparamss.head) ~~ valDefText(nameIdText(tree)), tree.vparamss.tail)
770770
else (defKeyword ~~ valDefText(nameIdText(tree)), tree.vparamss)
771771

772772
addVparamssText(prefix ~ tparamsText(tree.tparams), vparamss) ~

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -433,14 +433,7 @@ trait Inferencing { this: Typer =>
433433
else if (!hasUnreportedErrors)
434434
if (v.intValue != 0) {
435435
typr.println(i"interpolate $tvar in $state in $tree: $tp, fromBelow = ${v.intValue == 1}, $constraint")
436-
if (true) {
437-
val fromBelow = v.intValue == 1
438-
val instType = ctx.typeComparer.instanceType(tvar.origin, fromBelow)
439-
if (!(fromBelow && instType.isRef(defn.NothingClass)))
440-
tvar.instantiateWith(instType)
441-
}
442-
else
443-
tvar.instantiate(fromBelow = v.intValue == 1)
436+
tvar.instantiate(fromBelow = v.intValue == 1)
444437
}
445438
else typr.println(i"no interpolation for nonvariant $tvar in $state")
446439
}
File renamed without changes.
File renamed without changes.

tests/pos/i7149.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
trait ZIO[-R, +E, +A] { self =>
2+
3+
final def +++[R1, B, E1 >: E](that: ZIO[R1, E1, B]): ZIO[Either[R, R1], E1, Either[A, B]] =
4+
for {
5+
e <- ZIO.environment[Either[R, R1]]
6+
r <- e.fold(self.map(Left(_)) provide _, that.map(Right(_)) provide _)
7+
} yield r
8+
// Found: (Left[A, Any] | Right[Any, B])(r)
9+
// Required: Either[A, B]
10+
11+
def flatMap[R1 <: R, E1 >: E, B](f: A => ZIO[R1, E1, B]): ZIO[R1, E1, B] = ???
12+
13+
def map[B](f: A => B): ZIO[R, E, B] = ???
14+
15+
def provide[R](R: R): ZIO[Any, E, A] = ???
16+
}
17+
18+
object ZIO {
19+
def environment[R]: ZIO[R, Nothing, R] = ???
20+
}

tests/run/type-propagation.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
object Test extends App {
2-
def foo: String = {
2+
def foo: String =
33
"abc".asInstanceOf
4-
}
54

65
assert(foo == "abc")
76
}

0 commit comments

Comments
 (0)