diff --git a/community-build/community-projects/fastparse b/community-build/community-projects/fastparse index d13f34b47079..001c69755f99 160000 --- a/community-build/community-projects/fastparse +++ b/community-build/community-projects/fastparse @@ -1 +1 @@ -Subproject commit d13f34b470790536bf64deed062b7da53b098c05 +Subproject commit 001c69755f994ad222c7a903617ba8064ec93f41 diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 0bd18a7f122e..2f60b5774ad8 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -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") } @@ -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 ‘}’) @@ -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 diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 0c31d25f9e06..61ee8d804ba9 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -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) ~ diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index 06c9f1e51443..45c7c74ae459 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -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") } diff --git a/tests/pending/pos/enum-interop.scala b/tests/pos/enum-interop.scala similarity index 100% rename from tests/pending/pos/enum-interop.scala rename to tests/pos/enum-interop.scala diff --git a/tests/neg/i536.scala b/tests/pos/i536.scala similarity index 100% rename from tests/neg/i536.scala rename to tests/pos/i536.scala diff --git a/tests/pos/i7149.scala b/tests/pos/i7149.scala new file mode 100644 index 000000000000..c1180c2383ba --- /dev/null +++ b/tests/pos/i7149.scala @@ -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] = ??? +} \ No newline at end of file diff --git a/tests/run/type-propagation.scala b/tests/run/type-propagation.scala index b01d716269ac..070a6826e009 100644 --- a/tests/run/type-propagation.scala +++ b/tests/run/type-propagation.scala @@ -1,7 +1,6 @@ object Test extends App { - def foo: String = { + def foo: String = "abc".asInstanceOf - } assert(foo == "abc") }