diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index fd09af8a9ee5..bbde5522484b 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -766,7 +766,7 @@ object desugar { } flatTree(cdef1 :: companions ::: implicitWrappers) - }.reporting(res => i"desugared: $res", Printers.desugar) + }.reporting(i"desugared: $result", Printers.desugar) /** Expand * diff --git a/compiler/src/dotty/tools/dotc/core/Decorators.scala b/compiler/src/dotty/tools/dotc/core/Decorators.scala index 37a6e3e10c4f..0ca6b7f86c98 100644 --- a/compiler/src/dotty/tools/dotc/core/Decorators.scala +++ b/compiler/src/dotty/tools/dotc/core/Decorators.scala @@ -1,4 +1,5 @@ -package dotty.tools.dotc +package dotty.tools +package dotc package core import annotation.tailrec @@ -168,11 +169,16 @@ object Decorators { } } - implicit class genericDeco[T](val x: T) extends AnyVal { - def reporting(op: T => String, printer: config.Printers.Printer = config.Printers.default): T = { - printer.println(op(x)) + implicit object reportDeco { + def (x: T) reporting[T]( + op: given WrappedResult[T] => String, + printer: config.Printers.Printer = config.Printers.default): T = { + printer.println(op given WrappedResult(x)) x } + } + + implicit class genericDeco[T](val x: T) extends AnyVal { def assertingErrorsReported(implicit ctx: Context): T = { assert(ctx.reporter.errorsReported) x diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 331d593a2644..e15a4ba59025 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -757,8 +757,8 @@ object Denotations { def atSignature(sig: Signature, site: Type, relaxed: Boolean)(implicit ctx: Context): SingleDenotation = { val situated = if (site == NoPrefix) this else asSeenFrom(site) - val matches = sig.matchDegree(situated.signature) >= - (if (relaxed) Signature.ParamMatch else Signature.FullMatch) + val matches = sig.matchDegree(situated.signature).ordinal >= + (if (relaxed) Signature.ParamMatch else Signature.FullMatch).ordinal if (matches) this else NoDenotation } @@ -1096,7 +1096,7 @@ object Denotations { d == Signature.FullMatch && !infoOrCompleter.isInstanceOf[PolyType] && !other.infoOrCompleter.isInstanceOf[PolyType] || - d >= Signature.ParamMatch && info.matches(other.info)) + d != Signature.NoMatch && info.matches(other.info)) } def mapInherited(ownDenots: PreDenotation, prevDenots: PreDenotation, pre: Type)(implicit ctx: Context): SingleDenotation = diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 464807e98a35..3de27b232634 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -20,11 +20,7 @@ object Flags { opaque type Flag <: FlagSet = Long private[Flags] def Flag(bits: Long): Flag = bits } - type FlagSet = opaques.FlagSet - def FlagSet(bits: Long): FlagSet = opaques.FlagSet(bits) - // DOTTY TODO: replace previous 2 lines with - // export opaques.FlagSet - // once 0.17 is released and #6721 is in the bootstrap + export opaques.FlagSet type Flag = opaques.Flag diff --git a/compiler/src/dotty/tools/dotc/core/GadtConstraint.scala b/compiler/src/dotty/tools/dotc/core/GadtConstraint.scala index 11b869b8f995..e31821e2b5e0 100644 --- a/compiler/src/dotty/tools/dotc/core/GadtConstraint.scala +++ b/compiler/src/dotty/tools/dotc/core/GadtConstraint.scala @@ -123,9 +123,8 @@ final class ProperGadtConstraint private( } // The replaced symbols are picked up here. - addToConstraint(poly1, tvars).reporting({ _ => - i"added to constraint: $params%, %\n$debugBoundsDescription" - }, gadts) + addToConstraint(poly1, tvars) + .reporting(i"added to constraint: $params%, %\n$debugBoundsDescription", gadts) } override def addBound(sym: Symbol, bound: Type, isUpper: Boolean)(implicit ctx: Context): Boolean = { @@ -159,7 +158,7 @@ final class ProperGadtConstraint private( val oldUpperBound = bounds(symTvar.origin) // If we have bounds: // F >: [t] => List[t] <: [t] => Any - // and we want to record that: + // and we want to record that: // F <: [+A] => List[A] // we need to adapt the variance and instead record that: // F <: [A] => List[A] @@ -177,10 +176,10 @@ final class ProperGadtConstraint private( if (isUpper) addUpperBound(symTvar.origin, bound1) else addLowerBound(symTvar.origin, bound1) } - ).reporting({ res => + ).reporting({ val descr = if (isUpper) "upper" else "lower" val op = if (isUpper) "<:" else ">:" - i"adding $descr bound $sym $op $bound = $res" + i"adding $descr bound $sym $op $bound = $result" }, gadts) } @@ -206,7 +205,7 @@ final class ProperGadtConstraint private( case tb => tb } retrieveBounds - //.reporting({ res => i"gadt bounds $sym: $res" }, gadts) + //.reporting(i"gadt bounds $sym: $result", gadts) //.ensuring(containsNoInternalTypes(_)) } } diff --git a/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala b/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala index 740882a1cc63..76d5ac88d38c 100644 --- a/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala +++ b/compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala @@ -548,7 +548,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, merge(this.boundsMap, that.boundsMap, mergeEntries), merge(this.lowerMap, that.lowerMap, mergeParams), merge(this.upperMap, that.upperMap, mergeParams)) - }.reporting(res => i"constraint merge $this with $other = $res", constr) + }.reporting(i"constraint merge $this with $other = $result", constr) def rename(tl: TypeLambda)(implicit ctx: Context): OrderingConstraint = { assert(contains(tl)) diff --git a/compiler/src/dotty/tools/dotc/core/Signature.scala b/compiler/src/dotty/tools/dotc/core/Signature.scala index 4999c9eb90be..977bcef3f252 100644 --- a/compiler/src/dotty/tools/dotc/core/Signature.scala +++ b/compiler/src/dotty/tools/dotc/core/Signature.scala @@ -107,10 +107,10 @@ case class Signature(paramsSig: List[TypeName], resSig: TypeName) { object Signature { - type MatchDegree = Int - val NoMatch: Int = 0 - val ParamMatch: Int = 1 - val FullMatch: Int = 2 + enum MatchDegree { + case NoMatch, ParamMatch, FullMatch + } + export MatchDegree._ /** The signature of everything that's not a method, i.e. that has * a type different from PolyType, MethodType, or ExprType. diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 67ee4bd91d0f..df91418e7979 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -187,46 +187,34 @@ object SymDenotations { if (isCurrent(fs)) myFlags else flags /** Has this denotation one of given flag set? */ - final def is(flag: Flag)(implicit ctx: Context): Boolean = { - val toTest = if (isCurrent(flag)) myFlags else flags // TODO: combine these two lines once 0.17 is released and #6706 is in - toTest.is(flag) - } + final def is(flag: Flag)(implicit ctx: Context): Boolean = + (if (isCurrent(flag)) myFlags else flags).is(flag) /** Has this denotation one of the flags in `fs` set? */ - final def isOneOf(fs: FlagSet)(implicit ctx: Context): Boolean = { - val toTest = if (isCurrent(fs)) myFlags else flags // TODO: combine these two lines once 0.17 is released and #6706 is in - toTest.isOneOf(fs) - } + final def isOneOf(fs: FlagSet)(implicit ctx: Context): Boolean = + (if (isCurrent(fs)) myFlags else flags).isOneOf(fs) /** Has this denotation the given flag set, whereas none of the flags * in `butNot` are set? */ - final def is(flag: Flag, butNot: FlagSet)(implicit ctx: Context): Boolean = { - val toTest = if (isCurrent(flag) && isCurrent(butNot)) myFlags else flags // TODO: combine these two lines once 0.17 is released and #6706 is in - toTest.is(flag, butNot) - } + final def is(flag: Flag, butNot: FlagSet)(implicit ctx: Context): Boolean = + (if (isCurrent(flag) && isCurrent(butNot)) myFlags else flags).is(flag, butNot) /** Has this denotation one of the flags in `fs` set, whereas none of the flags * in `butNot` are set? */ - final def isOneOf(fs: FlagSet, butNot: FlagSet)(implicit ctx: Context): Boolean = { - val toTest = if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags // TODO: combine these two lines once 0.17 is released and #6706 is in - toTest.isOneOf(fs, butNot) - } + final def isOneOf(fs: FlagSet, butNot: FlagSet)(implicit ctx: Context): Boolean = + (if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags).isOneOf(fs, butNot) /** Has this denotation all of the flags in `fs` set? */ - final def isAllOf(fs: FlagSet)(implicit ctx: Context): Boolean = { - val toTest = if (isCurrent(fs)) myFlags else flags // TODO: combine these two lines once 0.17 is released and #6706 is in - toTest.isAllOf(fs) - } + final def isAllOf(fs: FlagSet)(implicit ctx: Context): Boolean = + (if (isCurrent(fs)) myFlags else flags).isAllOf(fs) /** Has this denotation all of the flags in `fs` set, whereas none of the flags * in `butNot` are set? */ - final def isAllOf(fs: FlagSet, butNot: FlagSet)(implicit ctx: Context): Boolean = { - val toTest = if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags // TODO: combine these two lines once 0.17 is released and #6706 is in - toTest.isAllOf(fs, butNot) - } + final def isAllOf(fs: FlagSet, butNot: FlagSet)(implicit ctx: Context): Boolean = + (if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags).isAllOf(fs, butNot) /** The type info, or, if symbol is not yet completed, the completer */ final def infoOrCompleter: Type = myInfo diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index 496eacbdf546..11e57c3f9233 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -782,7 +782,7 @@ object Symbols { } sourceFromTopLevel(ctx.withPhaseNoLater(ctx.flattenPhase)) } - }//.reporting(res => i"source of $this # $id in ${denot.owner} = $res") + }//.reporting(i"source of $this # $id in ${denot.owner} = $result") mySource } diff --git a/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala b/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala index ce15d818260b..1b28cbc8996a 100644 --- a/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala +++ b/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala @@ -119,7 +119,7 @@ trait MessageRendering { else s"${pos.source.file.toString}: offset ${pos.start} (missing source file)" val errId = if (message.errorId ne ErrorMessageID.NoExplanationID) { - val errorNumber = message.errorId.errorNumber() + val errorNumber = message.errorId.errorNumber s"[E${"0" * (3 - errorNumber.toString.length) + errorNumber}] " } else "" val kind = diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.scala similarity index 95% rename from compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java rename to compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.scala index b84b2cf17af7..bbfe6c1e505a 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.scala @@ -1,10 +1,10 @@ -package dotty.tools.dotc.reporting.diagnostic; +package dotty.tools.dotc.reporting.diagnostic /** Unique IDs identifying the messages */ -public enum ErrorMessageID { - - // IMPORTANT: Add new IDs only at the end and never remove IDs +enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] { + // IMPORTANT: Add new IDs only at the end and never remove IDs + case LazyErrorId, // // errorNumber: -2 NoExplanationID, // errorNumber: -1 @@ -146,10 +146,6 @@ public enum ErrorMessageID { StableIdentPatternID, StaticFieldsShouldPrecedeNonStaticID, IllegalSuperAccessorID - ; - - public int errorNumber() { - return ordinal() - 2; - } + def errorNumber = ordinal - 2 } diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 675365864c98..1d37ba7c8edf 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -2154,11 +2154,13 @@ object messages { val details = if (decl.isRealMethod && previousDecl.isRealMethod) { // compare the signatures when both symbols represent methods decl.signature.matchDegree(previousDecl.signature) match { - case Signature.NoMatch => + case Signature.MatchDegree.NoMatch => + // DOTTY problem: Need to qualify MatchDegree enum vals since otherwise exhaustivity fails. + // To fix this, we need to export vals under singleton types. "" // shouldn't be reachable - case Signature.ParamMatch => + case Signature.MatchDegree.ParamMatch => "have matching parameter types." - case Signature.FullMatch => + case Signature.MatchDegree.FullMatch => i"have the same$nameAnd type after erasure." } } else "" diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index 0e2dddf69555..3d2d674f5730 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -17,8 +17,6 @@ import dotty.tools.dotc.util.SourceFile import scala.tasty.reflect.Kernel -import delegate Flags.FlagOps // DOTTY problem: this line can be dropped in 0.17 once #6712 is in bootstrap. - class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.SourcePosition) extends Kernel { private implicit def ctx: core.Contexts.Context = rootContext diff --git a/compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala b/compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala index a573618d90d1..98a3cb12d54e 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala @@ -43,7 +43,10 @@ class CheckReentrant extends MiniPhase { def isIgnored(sym: Symbol)(implicit ctx: Context): Boolean = sym.hasAnnotation(sharableAnnot()) || - sym.hasAnnotation(unsharedAnnot()) + sym.hasAnnotation(unsharedAnnot()) || + sym.owner == defn.EnumValuesClass + // enum values are initialized eagerly before use + // in the long run, we should make them vals def scanning(sym: Symbol)(op: => Unit)(implicit ctx: Context): Unit = { ctx.log(i"${" " * indent}scanning $sym") diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 4595720091b2..76b669d9c655 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -628,7 +628,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { if (idx >= 0 && idx < args.length) { def finish(arg: Tree) = new TreeTypeMap().transform(arg) // make sure local bindings in argument have fresh symbols - .reporting(res => i"projecting $tree -> $res", inlining) + .reporting(i"projecting $tree -> $result", inlining) val arg = args(idx) if (precomputed) if (isPureExpr(arg)) finish(arg) diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index f96a0c761503..9eafce747966 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -401,7 +401,7 @@ object ProtoTypes { resType match { case SelectionProto(name: TermName, mbrType, _, _) => ctx.typer.hasExtensionMethod(tp, name, argType, mbrType) - //.reporting(res => i"has ext $tp $name $argType $mbrType: $res") + //.reporting(i"has ext $tp $name $argType $mbrType: $result") case _ => false } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 3621d093c897..24f605eb6310 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2565,7 +2565,7 @@ class Typer extends Namer typed(untpd.Select(untpd.New(untpd.TypedSplice(tpt)), nme.CONSTRUCTOR), pt) } recur(tycon, pt) - .reporting(res => i"try new $tree -> $res", typr) + .reporting(i"try new $tree -> $result", typr) } } { (nu, nuState) => if (nu.isEmpty) fallBack diff --git a/compiler/src/dotty/tools/dotc/typer/Variances.scala b/compiler/src/dotty/tools/dotc/typer/Variances.scala index 05570bac0bbe..014c23c961ee 100644 --- a/compiler/src/dotty/tools/dotc/typer/Variances.scala +++ b/compiler/src/dotty/tools/dotc/typer/Variances.scala @@ -3,7 +3,6 @@ package typer import core._ import Types._, Contexts._, Flags._, Symbols._, Annotations._ -import delegate Flags.FlagOps // DOTTY problem: this line can be dropped in 0.17 once #6712 is in bootstrap. object Variances { diff --git a/compiler/src/dotty/tools/package.scala b/compiler/src/dotty/tools/package.scala index 2a7506da8d52..416504d40aa4 100644 --- a/compiler/src/dotty/tools/package.scala +++ b/compiler/src/dotty/tools/package.scala @@ -23,4 +23,13 @@ package object tools { /** Throws an `UnsupportedOperationException` with the given method name. */ def unsupported(methodName: String): Nothing = throw new UnsupportedOperationException(methodName) + + object resultWrapper { + opaque type WrappedResult[T] = T + private[tools] def unwrap[T](x: WrappedResult[T]): T = x + private[tools] def wrap[T](x: T): WrappedResult[T] = x + } + type WrappedResult[T] = resultWrapper.WrappedResult[T] + def WrappedResult[T](x: T) = resultWrapper.wrap(x) + def result[T] given (x: WrappedResult[T]): T = resultWrapper.unwrap(x) }