From 2f001a93efad75d8bdfb184b4cced3de5b7aa14b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 24 May 2019 12:18:42 +0200 Subject: [PATCH 01/25] Drop FlagSet#toString This is in preparation of making Flags an opaque type --- .../src/dotty/tools/backend/jvm/DottyBackendInterface.scala | 2 +- compiler/src/dotty/tools/dotc/core/Flags.scala | 4 ++-- compiler/src/dotty/tools/dotc/core/SymDenotations.scala | 2 ++ compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 2 +- compiler/src/dotty/tools/dotc/transform/Bridges.scala | 2 +- compiler/src/dotty/tools/dotc/transform/TreeChecker.scala | 2 +- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 4 ++-- compiler/test/dotty/tools/dotc/ast/DesugarTests.scala | 2 +- .../test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala | 4 ++-- 9 files changed, 13 insertions(+), 11 deletions(-) diff --git a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index c758c3272af5..914a659c5ef0 100644 --- a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -261,7 +261,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma val evalue = t.symbol.name.mangledString // value the actual enumeration value. av.visitEnum(name, edesc, evalue) } else { - // println(i"not an enum: ${t.symbol} / ${t.symbol.denot.owner} / ${t.symbol.denot.owner.isTerm} / ${t.symbol.denot.owner.flags}") + // println(i"not an enum: ${t.symbol} / ${t.symbol.denot.owner} / ${t.symbol.denot.owner.isTerm} / ${t.symbol.denot.owner.flagsString}") assert(toDenot(t.symbol).name.is(DefaultGetterName), s"${toDenot(t.symbol).name.debugString}") // this should be default getter. do not emit. } diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index a9fff5f11c94..d8cfa91fed8a 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -122,7 +122,7 @@ object Flags { } /** The string representation of this flag set */ - override def toString: String = flagStrings("").mkString(" ") + def flagsString: String = flagStrings("").mkString(" ") } def termFlagSet(x: Long) = FlagSet(TERMS | x) @@ -132,7 +132,7 @@ object Flags { * `x is fc` tests whether `x` contains all flags in `fc`. */ case class FlagConjunction(bits: Long) { - override def toString: String = FlagSet(bits).toString + def flagsString: String = FlagSet(bits).flagsString def | (fs: FlagSet): FlagConjunction = FlagConjunction((FlagSet(bits) | fs).bits) } diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index d44316e38d09..47d5beb27106 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -154,6 +154,8 @@ object SymDenotations { */ private[dotc] final def flagsUNSAFE: FlagSet = myFlags + final def flagsString(implicit ctx: Context): String = flags.flagsString + /** Adapt flag set to this denotation's term or type nature */ private def adaptFlags(flags: FlagSet) = if (isType) flags.toTypeFlags else flags.toTermFlags diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 11bd30a35e4d..e2e826faf5a2 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2049,7 +2049,7 @@ object Parsers { val name = in.name val mod = atSpan(in.skipToken()) { modOfToken(tok, name) } - if (mods is mod.flags) syntaxError(RepeatedModifier(mod.flags.toString)) + if (mods is mod.flags) syntaxError(RepeatedModifier(mod.flags.flagsString)) addMod(mods, mod) } diff --git a/compiler/src/dotty/tools/dotc/transform/Bridges.scala b/compiler/src/dotty/tools/dotc/transform/Bridges.scala index 884d5c71f2fd..e51822c7c4b9 100644 --- a/compiler/src/dotty/tools/dotc/transform/Bridges.scala +++ b/compiler/src/dotty/tools/dotc/transform/Bridges.scala @@ -91,7 +91,7 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont ctx.debuglog( i"""generating bridge from ${other.showLocated}: ${other.info} |to ${member.showLocated}: ${member.info} @ ${member.span} - |bridge: ${bridge.showLocated} with flags: ${bridge.flags}""") + |bridge: ${bridge.showLocated} with flags: ${bridge.flagsString}""") bridgeTarget(bridge) = member bridgesScope.enter(bridge) diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index 375d11bedc30..89b1af7c6a35 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -392,7 +392,7 @@ class TreeChecker extends Phase with SymTransformer { assert(vparam.symbol.is(Param), s"Parameter ${vparam.symbol} of ${sym.fullName} does not have flag `Param` set") assert(!vparam.symbol.is(AccessFlags), - s"Parameter ${vparam.symbol} of ${sym.fullName} has invalid flag(s): ${vparam.symbol.flags & AccessFlags}") + s"Parameter ${vparam.symbol} of ${sym.fullName} has invalid flag(s): ${(vparam.symbol.flags & AccessFlags).flagsString}") }) val tpdTree = super.typedDefDef(ddef, sym) diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index fa53f1070ba5..bd0ccac499dc 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -261,8 +261,8 @@ object RefChecks { sym.is(Module)) // synthetic companion def overrideAccessError() = { - ctx.log(i"member: ${member.showLocated} ${member.flags}") // DEBUG - ctx.log(i"other: ${other.showLocated} ${other.flags}") // DEBUG + ctx.log(i"member: ${member.showLocated} ${member.flagsString}") // DEBUG + ctx.log(i"other: ${other.showLocated} ${other.flagsString}") // DEBUG val otherAccess = (other.flags & AccessFlags).toString overrideError("has weaker access privileges; it should be " + (if (otherAccess == "") "public" else "at least " + otherAccess)) diff --git a/compiler/test/dotty/tools/dotc/ast/DesugarTests.scala b/compiler/test/dotty/tools/dotc/ast/DesugarTests.scala index c61773c84015..eb08ca66fbc5 100644 --- a/compiler/test/dotty/tools/dotc/ast/DesugarTests.scala +++ b/compiler/test/dotty/tools/dotc/ast/DesugarTests.scala @@ -17,7 +17,7 @@ class DesugarTests extends DottyTest { sym.is(Synthetic) || // or be a constructor: sym.name == nme.CONSTRUCTOR, - s"found: $sym (${sym.flags})" + s"found: $sym (${sym.flagsString})" ) } diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index fe4ae0dd5af5..c4eef15a30cf 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -702,7 +702,7 @@ class ErrorMessagesTests extends ErrorMessagesTest { assertMessageCount(1, messages) val AbstractMemberMayNotHaveModifier(symbol, flags) :: Nil = messages assertEquals("value s", symbol.show) - assertEquals("final", flags.toString) + assertEquals("final", flags.flagsString) } @Test def typesAndTraitsCantBeImplicit = @@ -1018,7 +1018,7 @@ class ErrorMessagesTests extends ErrorMessagesTest { implicit val ctx: Context = ictx assertMessageCount(1, messages) val ModifiersNotAllowed(flags, sort) :: Nil = messages - assertEquals(modifierAssertion, flags.toString) + assertEquals(modifierAssertion, flags.flagsString) assertEquals(typeAssertion, sort) } } From 31f9fedd7356c2a5afebee5f1df1d04213d258f7 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 24 May 2019 16:03:25 +0200 Subject: [PATCH 02/25] Drop implicit FlagConjunction -> FlagSet conversion and don't overload `is`. FlagConjunction tests are now called `isAll`. --- .../tools/backend/jvm/DottyBackendInterface.scala | 8 ++++---- compiler/src/dotty/tools/dotc/ast/Desugar.scala | 8 ++++---- compiler/src/dotty/tools/dotc/ast/Trees.scala | 2 +- compiler/src/dotty/tools/dotc/ast/untpd.scala | 8 ++++---- .../src/dotty/tools/dotc/config/JavaPlatform.scala | 2 +- .../src/dotty/tools/dotc/core/Definitions.scala | 6 +++--- .../src/dotty/tools/dotc/core/Denotations.scala | 4 ++-- compiler/src/dotty/tools/dotc/core/Flags.scala | 13 ++++++------- .../src/dotty/tools/dotc/core/SymDenotations.scala | 8 ++++---- compiler/src/dotty/tools/dotc/core/Symbols.scala | 4 ++-- compiler/src/dotty/tools/dotc/core/Types.scala | 8 ++++---- .../tools/dotc/core/classfile/ClassfileParser.scala | 10 +++++----- .../dotc/core/unpickleScala2/Scala2Unpickler.scala | 4 ++-- .../dotty/tools/dotc/interactive/Completion.scala | 2 +- .../src/dotty/tools/dotc/parsing/JavaParsers.scala | 10 +++++----- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 12 ++++++------ .../dotty/tools/dotc/printing/PlainPrinter.scala | 2 +- .../dotty/tools/dotc/printing/RefinedPrinter.scala | 4 ++-- compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala | 4 ++-- .../dotty/tools/dotc/tastyreflect/KernelImpl.scala | 2 +- .../tools/dotc/transform/AugmentScala2Traits.scala | 2 +- .../dotc/transform/CollectNullableFields.scala | 2 +- .../dotty/tools/dotc/transform/Constructors.scala | 6 +++--- .../dotty/tools/dotc/transform/ExpandPrivate.scala | 4 ++-- .../src/dotty/tools/dotc/transform/Getters.scala | 2 +- .../tools/dotc/transform/LinkScala2Impls.scala | 2 +- compiler/src/dotty/tools/dotc/transform/Mixin.scala | 4 ++-- .../tools/dotc/transform/PCPCheckAndHeal.scala | 2 +- .../dotty/tools/dotc/transform/PatternMatcher.scala | 2 +- .../dotty/tools/dotc/transform/SelectStatic.scala | 2 +- .../src/dotty/tools/dotc/transform/Splicer.scala | 2 +- .../dotty/tools/dotc/transform/SuperAccessors.scala | 2 +- .../dotty/tools/dotc/transform/TreeChecker.scala | 2 +- .../dotty/tools/dotc/transform/patmat/Space.scala | 8 ++++---- .../src/dotty/tools/dotc/typer/Applications.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Checking.scala | 4 ++-- compiler/src/dotty/tools/dotc/typer/Inliner.scala | 4 ++-- compiler/src/dotty/tools/dotc/typer/Namer.scala | 4 ++-- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 4 ++-- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- .../dotty/tools/dotc/typer/VarianceChecker.scala | 6 +++--- 41 files changed, 94 insertions(+), 95 deletions(-) diff --git a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index 914a659c5ef0..7fe2743e0d16 100644 --- a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -256,7 +256,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma case t: TypeApply if (t.fun.symbol == Predef_classOf) => av.visit(name, t.args.head.tpe.classSymbol.denot.info.toTypeKind(bcodeStore)(innerClasesStore).toASMType) case t: tpd.RefTree => - if (t.symbol.denot.owner.is(Flags.JavaEnum)) { + if (t.symbol.denot.owner.isAll(Flags.JavaEnum)) { val edesc = innerClasesStore.typeDescriptor(t.tpe.asInstanceOf[bcodeStore.int.Type]) // the class descriptor of the enumeration class. val evalue = t.symbol.name.mangledString // value the actual enumeration value. av.visitEnum(name, edesc, evalue) @@ -477,7 +477,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma // unrelated change. ctx.base.settings.YnoGenericSig.value || sym.is(Flags.Artifact) - || sym.is(Flags.LiftedMethod) + || sym.isAll(Flags.LiftedMethod) || sym.is(Flags.Bridge) ) @@ -689,13 +689,13 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma def isBottomClass: Boolean = (sym ne defn.NullClass) && (sym ne defn.NothingClass) def isBridge: Boolean = sym is Flags.Bridge def isArtifact: Boolean = sym is Flags.Artifact - def hasEnumFlag: Boolean = sym is Flags.JavaEnum + def hasEnumFlag: Boolean = sym.isAll(Flags.JavaEnum) def hasAccessBoundary: Boolean = sym.accessBoundary(defn.RootClass) ne defn.RootClass def isVarargsMethod: Boolean = sym is Flags.JavaVarargs def isDeprecated: Boolean = false def isMutable: Boolean = sym is Flags.Mutable def hasAbstractFlag: Boolean = - (sym is Flags.Abstract) || (sym is Flags.JavaInterface) || (sym is Flags.Trait) + (sym is Flags.Abstract) || (sym.isAll(Flags.JavaInterface)) || (sym is Flags.Trait) def hasModuleFlag: Boolean = sym is Flags.Module def isSynchronized: Boolean = sym is Flags.Synchronized def isNonBottomSubClass(other: Symbol): Boolean = sym.derivesFrom(other) diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 3b710ec34f5f..62a87138d57a 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -159,7 +159,7 @@ object desugar { val vdef @ ValDef(name, tpt, rhs) = transformQuotedPatternName(vdef0) val mods = vdef.mods val setterNeeded = - (mods is Mutable) && ctx.owner.isClass && (!(mods is PrivateLocal) || (ctx.owner is Trait)) + (mods is Mutable) && ctx.owner.isClass && (!mods.isAll(PrivateLocal) || (ctx.owner is Trait)) if (setterNeeded) { // TODO: copy of vdef as getter needed? // val getter = ValDef(mods, name, tpt, rhs) withPos vdef.pos? @@ -182,7 +182,7 @@ object desugar { def makeImplicitParameters(tpts: List[Tree], implicitFlag: FlagSet, forPrimaryConstructor: Boolean = false)(implicit ctx: Context): List[ValDef] = for (tpt <- tpts) yield { - val paramFlags: FlagSet = if (forPrimaryConstructor) PrivateLocalParamAccessor else Param + val paramFlags: FlagSet = if (forPrimaryConstructor) PrivateLocalParamAccessor.toFlags else Param val epname = EvidenceParamName.fresh() ValDef(epname, tpt, EmptyTree).withFlags(paramFlags | implicitFlag) } @@ -403,7 +403,7 @@ object desugar { val tparamReferenced = typeParamIsReferenced( enumClass.typeParams, originalTparams, originalVparamss, parents) if (originalTparams.isEmpty && (parents.isEmpty || tparamReferenced)) - derivedEnumParams.map(tdef => tdef.withFlags(tdef.mods.flags | PrivateLocal)) + derivedEnumParams.map(tdef => tdef.withFlags(tdef.mods.flags | PrivateLocal.toFlags)) else originalTparams } else originalTparams @@ -974,7 +974,7 @@ object desugar { case _ => val tmpName = UniqueName.fresh() val patMods = - mods & Lazy | Synthetic | (if (ctx.owner.isClass) PrivateLocal else EmptyFlags) + mods & Lazy | Synthetic | (if (ctx.owner.isClass) PrivateLocal.toFlags else EmptyFlags) val firstDef = ValDef(tmpName, TypeTree(), matchExpr) .withSpan(pat.span.union(rhs.span)).withMods(patMods) diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index ecbd63bc35f4..9763884684bd 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -866,7 +866,7 @@ object Trees { class EmptyValDef[T >: Untyped] extends ValDef[T]( nme.WILDCARD, genericEmptyTree[T], genericEmptyTree[T])(NoSource) with WithoutTypeOrPos[T] { myTpe = NoType.asInstanceOf[T] - setMods(untpd.Modifiers(PrivateLocal)) + setMods(untpd.Modifiers(PrivateLocal.toFlags)) override def isEmpty: Boolean = true override def withSpan(span: Span) = throw new AssertionError("Cannot change span of EmptyValDef") } diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index 9c1a798b3d4f..9deb73b54621 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -184,8 +184,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { mods: List[Mod] = Nil) { def is(fs: FlagSet): Boolean = flags is fs - def is(fc: FlagConjunction): Boolean = flags is fc - def is(fc: FlagSet, butNot: FlagSet): Boolean = flags.is(fc, butNot = butNot) + def is(fs: FlagSet, butNot: FlagSet): Boolean = flags.is(fs, butNot = butNot) + def isAll(fc: FlagConjunction): Boolean = flags.isAll(fc) def | (fs: FlagSet): Modifiers = withFlags(flags | fs) def & (fs: FlagSet): Modifiers = withFlags(flags & fs) @@ -413,7 +413,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { makeConstructor(Nil, Nil) def makeSelfDef(name: TermName, tpt: Tree)(implicit ctx: Context): ValDef = - ValDef(name, tpt, EmptyTree).withFlags(PrivateLocal) + ValDef(name, tpt, EmptyTree).withFlags(PrivateLocal.toFlags) def makeTupleOrParens(ts: List[Tree])(implicit ctx: Context): Tree = ts match { case t :: Nil => Parens(t) @@ -435,7 +435,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { vdef.withMods(mods | Param) } - def makeSyntheticParameter(n: Int = 1, tpt: Tree = null, flags: FlagSet = SyntheticTermParam)(implicit ctx: Context): ValDef = + def makeSyntheticParameter(n: Int = 1, tpt: Tree = null, flags: FlagSet = SyntheticTermParam.toFlags)(implicit ctx: Context): ValDef = ValDef(nme.syntheticParamName(n), if (tpt == null) TypeTree() else tpt, EmptyTree) .withFlags(flags) diff --git a/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala b/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala index cbcf3c703f1d..bd39be3297d9 100644 --- a/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala +++ b/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala @@ -39,7 +39,7 @@ class JavaPlatform extends Platform { /** Is the SAMType `cls` also a SAM under the rules of the JVM? */ def isSam(cls: ClassSymbol)(implicit ctx: Context): Boolean = - cls.is(NoInitsTrait) && + cls.isAll(NoInitsTrait) && cls.superClass == defn.ObjectClass && cls.directlyInheritedTraits.forall(_.is(NoInits)) && !ExplicitOuter.needsOuterIfReferenced(cls) && diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 07c1fb8d565a..194a418abb53 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -325,7 +325,7 @@ class Definitions { Object_finalize, Object_notify, Object_notifyAll, Object_wait, Object_waitL, Object_waitLI) @threadUnsafe lazy val AnyKindClass: ClassSymbol = { - val cls = ctx.newCompleteClassSymbol(ScalaPackageClass, tpnme.AnyKind, AbstractFinal | Permanent, Nil) + val cls = ctx.newCompleteClassSymbol(ScalaPackageClass, tpnme.AnyKind, AbstractFinal.toFlags | Permanent, Nil) if (!ctx.settings.YnoKindPolymorphism.value) { // Enable kind-polymorphism by exposing scala.AnyKind cls.entered @@ -348,11 +348,11 @@ class Definitions { MethodType(List(ThrowableType), NothingType)) @threadUnsafe lazy val NothingClass: ClassSymbol = enterCompleteClassSymbol( - ScalaPackageClass, tpnme.Nothing, AbstractFinal, List(AnyClass.typeRef)) + ScalaPackageClass, tpnme.Nothing, AbstractFinal.toFlags, List(AnyClass.typeRef)) def NothingType: TypeRef = NothingClass.typeRef @threadUnsafe lazy val RuntimeNothingModuleRef: TermRef = ctx.requiredModuleRef("scala.runtime.Nothing") @threadUnsafe lazy val NullClass: ClassSymbol = enterCompleteClassSymbol( - ScalaPackageClass, tpnme.Null, AbstractFinal, List(ObjectClass.typeRef)) + ScalaPackageClass, tpnme.Null, AbstractFinal.toFlags, List(ObjectClass.typeRef)) def NullType: TypeRef = NullClass.typeRef @threadUnsafe lazy val RuntimeNullModuleRef: TermRef = ctx.requiredModuleRef("scala.runtime.Null") diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index b041a69e171c..ec2e166c750a 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -1109,7 +1109,7 @@ object Denotations { final def filterDisjoint(denots: PreDenotation)(implicit ctx: Context): SingleDenotation = if (denots.exists && denots.matches(this)) NoDenotation else this def filterWithFlags(required: FlagConjunction, excluded: FlagSet)(implicit ctx: Context): SingleDenotation = - if (required.isEmpty && excluded.isEmpty || compatibleWith(required, excluded)) this else NoDenotation + if (required.toFlags.isEmpty && excluded.isEmpty || compatibleWith(required, excluded)) this else NoDenotation type AsSeenFromResult = SingleDenotation protected def computeAsSeenFrom(pre: Type)(implicit ctx: Context): SingleDenotation = { @@ -1152,7 +1152,7 @@ object Denotations { case symd: SymDenotation => symd case _ => symbol.denot } - symd.is(required) && !symd.is(excluded) + symd.isAll(required) && !symd.is(excluded) } } diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index d8cfa91fed8a..f65c8d5b716c 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -56,7 +56,7 @@ object Flags { /** Does this flag set have all of the flags in given flag conjunction? * Pre: The intersection of the typeflags of both sets must be non-empty. */ - def is(flags: FlagConjunction): Boolean = { + def isAll(flags: FlagConjunction): Boolean = { val fs = bits & flags.bits ((fs & KINDFLAGS) != 0 || flags.bits == 0) && (fs >>> TYPESHIFT) == (flags.bits >>> TYPESHIFT) @@ -66,7 +66,7 @@ object Flags { * and at the same time contain none of the flags in the `butNot` set? * Pre: The intersection of the typeflags of both sets must be non-empty. */ - def is(flags: FlagConjunction, butNot: FlagSet): Boolean = is(flags) && !is(butNot) + def isAll(flags: FlagConjunction, butNot: FlagSet): Boolean = isAll(flags) && !is(butNot) def isEmpty: Boolean = (bits & ~KINDFLAGS) == 0 @@ -132,8 +132,9 @@ object Flags { * `x is fc` tests whether `x` contains all flags in `fc`. */ case class FlagConjunction(bits: Long) { - def flagsString: String = FlagSet(bits).flagsString - def | (fs: FlagSet): FlagConjunction = FlagConjunction((FlagSet(bits) | fs).bits) + def toFlags = FlagSet(bits) + def flagsString: String = toFlags.flagsString + def | (fs: FlagSet): FlagConjunction = FlagConjunction((toFlags | fs).bits) } def termFlagConjunction(x: Long) = FlagConjunction(TERMS | x) @@ -733,7 +734,5 @@ object Flags { final val SyntheticTermParam: FlagConjunction = allOf(Synthetic, TermParam) final val SyntheticTypeParam: FlagConjunction = allOf(Synthetic, TypeParam) final val SyntheticCase: FlagConjunction = allOf(Synthetic, Case) - - implicit def conjToFlagSet(conj: FlagConjunction): FlagSet = - FlagSet(conj.bits) + final val SyntheticOpaque: FlagConjunction = allOf(Synthetic, Opaque) } diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 47d5beb27106..63a6eb722b89 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -197,14 +197,14 @@ object SymDenotations { (if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags) is (fs, butNot) /** Has this denotation all of the flags in `fs` set? */ - final def is(fs: FlagConjunction)(implicit ctx: Context): Boolean = - (if (isCurrent(fs)) myFlags else flags) is fs + final def isAll(fs: FlagConjunction)(implicit ctx: Context): Boolean = + (if (isCurrent(fs.toFlags)) myFlags else flags).isAll(fs) /** Has this denotation all of the flags in `fs` set, whereas none of the flags * in `butNot` are set? */ final def is(fs: FlagConjunction, butNot: FlagSet)(implicit ctx: Context): Boolean = - (if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags) is (fs, butNot) + (if (isCurrent(fs.toFlags) && isCurrent(butNot)) myFlags else flags).isAll(fs, butNot) /** The type info, or, if symbol is not yet completed, the completer */ final def infoOrCompleter: Type = myInfo @@ -1235,7 +1235,7 @@ object SymDenotations { final def accessBoundary(base: Symbol)(implicit ctx: Context): Symbol = { val fs = flags if (fs is Private) owner - else if (fs is StaticProtected) defn.RootClass + else if (fs.isAll(StaticProtected)) defn.RootClass else if (privateWithin.exists && !ctx.phase.erasedTypes) privateWithin else if (fs is Protected) base else defn.RootClass diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index 0b43e9763722..fe7bf0a7a95c 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -296,11 +296,11 @@ trait Symbols { this: Context => /** Create a new skolem symbol. This is not the same as SkolemType, even though the * motivation (create a singleton referencing to a type) is similar. */ - def newSkolem(tp: Type): TermSymbol = newSymbol(defn.RootClass, nme.SKOLEM, SyntheticArtifact | NonMember | Permanent, tp) + def newSkolem(tp: Type): TermSymbol = newSymbol(defn.RootClass, nme.SKOLEM, SyntheticArtifact.toFlags | NonMember | Permanent, tp) def newErrorSymbol(owner: Symbol, name: Name, msg: => Message): Symbol = { val errType = ErrorType(msg) - newSymbol(owner, name, SyntheticArtifact, + newSymbol(owner, name, SyntheticArtifact.toFlags, if (name.isTypeName) TypeAlias(errType) else errType) } diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 4efd12dcc734..0a58a968e8a3 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -235,7 +235,7 @@ object Types { * from the ThisType of `symd`'s owner. */ def isArgPrefixOf(symd: SymDenotation)(implicit ctx: Context): Boolean = - symd.is(ClassTypeParam) && { + symd.isAll(ClassTypeParam) && { this match { case tp: ThisType => tp.cls ne symd.owner case _ => true @@ -2149,7 +2149,7 @@ object Types { else { if (isType) { val res = - if (currentSymbol.is(ClassTypeParam)) argForParam(prefix) + if (currentSymbol.isAll(ClassTypeParam)) argForParam(prefix) else prefix.lookupRefined(name) if (res.exists) return res if (Config.splitProjections) @@ -4375,7 +4375,7 @@ object Types { // (x: String): Int val approxParams = new ApproximatingTypeMap { def apply(tp: Type): Type = tp match { - case tp: TypeRef if tp.symbol.is(ClassTypeParam) && tp.symbol.owner == cls => + case tp: TypeRef if tp.symbol.isAll(ClassTypeParam) && tp.symbol.owner == cls => tp.info match { case info: AliasingBounds => mapOver(info.alias) @@ -4717,7 +4717,7 @@ object Types { else pre match { case Range(preLo, preHi) => val forwarded = - if (tp.symbol.is(ClassTypeParam)) expandParam(tp, preHi) + if (tp.symbol.isAll(ClassTypeParam)) expandParam(tp, preHi) else tryWiden(tp, preHi) forwarded.orElse( range(super.derivedSelect(tp, preLo).loBound, super.derivedSelect(tp, preHi).hiBound)) diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 64b3f724adcd..661494ec19be 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -185,8 +185,8 @@ class ClassfileParser( if (isEnum) { instanceScope.toList.map(_.ensureCompleted()) staticScope.toList.map(_.ensureCompleted()) - classRoot.setFlag(Flags.JavaEnum) - moduleRoot.setFlag(Flags.JavaEnum) + classRoot.setFlag(Flags.JavaEnum.toFlags) + moduleRoot.setFlag(Flags.JavaEnum.toFlags) } result @@ -276,7 +276,7 @@ class ClassfileParser( if (!enumClass.exists) ctx.warning(s"no linked class for java enum $sym in ${sym.owner}. A referencing class file might be missing an InnerClasses entry.") else { - if (!(enumClass is Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed) + if (!(enumClass is Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed.toFlags) enumClass.addAnnotation(Annotation.Child(sym)) } } @@ -555,7 +555,7 @@ class ClassfileParser( if (ctx.debug && ctx.verbose) println("" + sym + "; signature = " + sig + " type = " + newType) case tpnme.SyntheticATTR => - sym.setFlag(Flags.SyntheticArtifact) + sym.setFlag(Flags.SyntheticArtifact.toFlags) case tpnme.BridgeATTR => sym.setFlag(Flags.Bridge) case tpnme.DeprecatedATTR => @@ -583,7 +583,7 @@ class ClassfileParser( parseExceptions(attrLen) case tpnme.CodeATTR => - if (sym.owner is Flags.JavaTrait) { + if (sym.owner.isAll(Flags.JavaTrait)) { sym.resetFlag(Flags.Deferred) sym.owner.resetFlag(Flags.PureInterface) ctx.log(s"$sym in ${sym.owner} is a java8+ default method.") diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 9bdd7607ec44..7941e2a71b59 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -120,7 +120,7 @@ object Scala2Unpickler { if (tsym.exists) tsym.setFlag(TypeParam) else denot.enter(tparam, decls) } - if (!(denot.flagsUNSAFE is JavaModule)) ensureConstructor(denot.symbol.asClass, decls) + if (!denot.flagsUNSAFE.isAll(JavaModule)) ensureConstructor(denot.symbol.asClass, decls) val scalacCompanion = denot.classSymbol.scalacLinkedClass @@ -436,7 +436,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas val owner = readSymbolRef() var flags = unpickleScalaFlags(readLongNat(), name.isTypeName) - if (flags is DefaultParameter) { + if (flags.isAll(DefaultParameter)) { // DefaultParameterized flag now on method, not parameter //assert(flags is Param, s"$name0 in $owner") flags = flags &~ DefaultParameterized diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index 7dca85b59152..684c8c4bf3f8 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -255,7 +255,7 @@ object Completion { !sym.isPrimaryConstructor && sym.sourceSymbol.exists && (!sym.is(Package) || sym.is(ModuleClass)) && - !sym.is(allOf(Mutable, Accessor)) && + !sym.isAll(allOf(Mutable, Accessor)) && !sym.isPackageObject && !sym.is(Artifact) && ( diff --git a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala index 692d99b053b0..f273a932698b 100644 --- a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala @@ -120,7 +120,7 @@ object JavaParsers { // This also avoids clashes between the constructor parameter names and member names. if (needsDummyConstr) { stats1 = constr1 :: stats1 - constr1 = makeConstructor(List(scalaDot(tpnme.Unit)), tparams, Flags.JavaDefined | Flags.PrivateLocal) + constr1 = makeConstructor(List(scalaDot(tpnme.Unit)), tparams, Flags.JavaDefined | Flags.PrivateLocal.toFlags) } Template(constr1.asInstanceOf[DefDef], parents, Nil, EmptyValDef, stats1) } @@ -401,7 +401,7 @@ object JavaParsers { throw new RuntimeException } - def typeParams(flags: FlagSet = Flags.JavaDefined | Flags.PrivateLocal | Flags.Param): List[TypeDef] = + def typeParams(flags: FlagSet = Flags.JavaDefined | Flags.PrivateLocal.toFlags | Flags.Param): List[TypeDef] = if (in.token == LT) { in.nextToken() val tparams = repsep(() => typeParam(flags), COMMA) @@ -711,7 +711,7 @@ object JavaParsers { val iface = atSpan(start, nameOffset) { TypeDef( name, - makeTemplate(parents, body, tparams, false)).withMods(mods | Flags.Trait | Flags.JavaInterface | Flags.Abstract) + makeTemplate(parents, body, tparams, false)).withMods(mods | Flags.Trait | Flags.JavaInterface.toFlags | Flags.Abstract) } addCompanionObject(statics, iface) } @@ -835,7 +835,7 @@ object JavaParsers { Select(New(javaLangDot(tpnme.Enum)), nme.CONSTRUCTOR), List(enumType)), Nil) val enumclazz = atSpan(start, nameOffset) { TypeDef(name, - makeTemplate(superclazz :: interfaces, body, List(), true)).withMods(mods | Flags.JavaEnum) + makeTemplate(superclazz :: interfaces, body, List(), true)).withMods(mods | Flags.JavaEnum.toFlags) } addCompanionObject(consts ::: statics ::: predefs, enumclazz) } @@ -854,7 +854,7 @@ object JavaParsers { skipAhead() accept(RBRACE) } - ValDef(name.toTermName, enumType, unimplementedExpr).withMods(Modifiers(Flags.JavaEnum | Flags.StableRealizable | Flags.JavaDefined | Flags.JavaStatic)) + ValDef(name.toTermName, enumType, unimplementedExpr).withMods(Modifiers(Flags.JavaEnum.toFlags | Flags.StableRealizable | Flags.JavaDefined | Flags.JavaStatic)) } } diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index e2e826faf5a2..ca30f41c2d6f 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1609,7 +1609,7 @@ object Parsers { case USCORE => val start = in.skipToken() val pname = WildcardParamName.fresh() - val param = ValDef(pname, TypeTree(), EmptyTree).withFlags(SyntheticTermParam) + val param = ValDef(pname, TypeTree(), EmptyTree).withFlags(SyntheticTermParam.toFlags) .withSpan(Span(start)) placeholderParams = param :: placeholderParams atSpan(start) { Ident(pname) } @@ -2039,7 +2039,7 @@ object Parsers { private def normalize(mods: Modifiers): Modifiers = if ((mods is Private) && mods.hasPrivateWithin) normalize(mods &~ Private) - else if (mods is AbstractAndOverride) + else if (mods.isAll(AbstractAndOverride)) normalize(addFlag(mods &~ (Abstract | Override), AbsOverride)) else mods @@ -2178,7 +2178,7 @@ object Parsers { val start = in.offset val mods = annotsAsMods() | { - if (ownerKind == ParamOwner.Class) Param | PrivateLocal + if (ownerKind == ParamOwner.Class) Param | PrivateLocal.toFlags else Param } | { if (ownerKind == ParamOwner.Def) EmptyFlags @@ -2243,7 +2243,7 @@ object Parsers { if (!(mods.flags &~ (ParamAccessor | Inline | impliedMods.flags)).isEmpty) syntaxError("`val' or `var' expected") if (firstClause && ofCaseClass) mods - else mods | PrivateLocal + else mods | PrivateLocal.toFlags } } else { @@ -2822,9 +2822,9 @@ object Parsers { } else { newLineOptWhenFollowedBy(LBRACE) - val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal)) + val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal.toFlags)) val vparamss1 = vparamss.map(_.map(vparam => - vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal))) + vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal.toFlags))) val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil) if (tparams.isEmpty && vparamss.isEmpty) ModuleDef(name, templ) else TypeDef(name.toTypeName, templ) diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index 9c4183892748..4beb0c36754f 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -391,7 +391,7 @@ class PlainPrinter(_ctx: Context) extends Printer { /** String representation of symbol's definition keyword */ protected def keyString(sym: Symbol): String = { val flags = sym.flagsUNSAFE - if (flags is JavaTrait) "interface" + if (flags.isAll(JavaTrait)) "interface" else if (flags is Trait) "trait" else if (flags is Module) "object" else if (sym.isClass) "class" diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 9e7257aca9dc..a7de29612c73 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -816,7 +816,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { protected def annotText(tree: untpd.Tree): Text = "@" ~ constrText(tree) // DD protected def modText(mods: untpd.Modifiers, sym: Symbol, kw: String, isType: Boolean): Text = { // DD - val suppressKw = if (enclDefIsClass) mods is ParamAndLocal else mods is Param + val suppressKw = if (enclDefIsClass) mods.isAll(ParamAndLocal) else mods.is(Param) var flagMask = if (ctx.settings.YdebugFlags.value) AnyFlags else if (suppressKw) PrintableFlags(isType) &~ Private @@ -847,7 +847,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { override protected def treatAsTypeParam(sym: Symbol): Boolean = sym is TypeParam override protected def treatAsTypeArg(sym: Symbol): Boolean = - sym.isType && (sym is ProtectedLocal) && + sym.isType && (sym.isAll(ProtectedLocal)) && (sym.allOverriddenSymbols exists (_ is TypeParam)) override def toText(sym: Symbol): Text = { diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala index e9374f7570fc..278529ad8ceb 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala @@ -567,9 +567,9 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder // but their `privateWithin` exists, see `Parsers#ParserCommon#normalize`. if (!sym.is(Protected | Private) && !sym.privateWithin.exists) Constants.public - else if (sym.is(PrivateLocal)) + else if (sym.isAll(PrivateLocal)) Constants.privateLocal - else if (sym.is(ProtectedLocal)) + else if (sym.isAll(ProtectedLocal)) Constants.protectedLocal else { val qualifier = diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index 1b5cfe9e8d95..70c883bdc241 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -1722,7 +1722,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def Flags_ParamAccessor: Flags = core.Flags.ParamAccessor def Flags_Enum: Flags = core.Flags.Enum def Flags_ModuleClass: Flags = core.Flags.ModuleClass - def Flags_PrivateLocal: Flags = core.Flags.PrivateLocal + def Flags_PrivateLocal: Flags = core.Flags.PrivateLocal.toFlags def Flags_Package: Flags = core.Flags.Package // diff --git a/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala b/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala index 655923ad3d6c..fae404e7ee12 100644 --- a/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala +++ b/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala @@ -59,7 +59,7 @@ class AugmentScala2Traits extends MiniPhase with IdentityDenotTransformer { this if (sym.isGetter && !sym.is(LazyOrDeferred) && !sym.setter.exists && !sym.info.resultType.isInstanceOf[ConstantType]) traitSetter(sym.asTerm).enteredAfter(thisPhase) - if ((sym.is(PrivateAccessor) && !sym.name.is(ExpandedName) && + if ((sym.isAll(PrivateAccessor) && !sym.name.is(ExpandedName) && (sym.isGetter || sym.isSetter)) // strangely, Scala 2 fields are also methods that have Accessor set. || sym.isSuperAccessor) // scala2 superaccessors are pickled as private, but are compiled as public expanded sym.ensureNotPrivate.installAfter(thisPhase) diff --git a/compiler/src/dotty/tools/dotc/transform/CollectNullableFields.scala b/compiler/src/dotty/tools/dotc/transform/CollectNullableFields.scala index bae91bf62417..c6fbd64c426d 100644 --- a/compiler/src/dotty/tools/dotc/transform/CollectNullableFields.scala +++ b/compiler/src/dotty/tools/dotc/transform/CollectNullableFields.scala @@ -64,7 +64,7 @@ class CollectNullableFields extends MiniPhase { sym.isField && !sym.is(Lazy) && !sym.owner.is(Trait) && - sym.initial.is(PrivateLocal) && + sym.initial.isAll(PrivateLocal) && sym.info.widenDealias.typeSymbol.isNullableClass if (isNullablePrivateField) diff --git a/compiler/src/dotty/tools/dotc/transform/Constructors.scala b/compiler/src/dotty/tools/dotc/transform/Constructors.scala index ecdb06326d54..32aad5c004f0 100644 --- a/compiler/src/dotty/tools/dotc/transform/Constructors.scala +++ b/compiler/src/dotty/tools/dotc/transform/Constructors.scala @@ -99,7 +99,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase = */ override def checkPostCondition(tree: tpd.Tree)(implicit ctx: Context): Unit = { def emptyRhsOK(sym: Symbol) = - sym.is(LazyOrDeferred) || sym.isConstructor && sym.owner.is(NoInitsTrait) + sym.is(LazyOrDeferred) || sym.isConstructor && sym.owner.isAll(NoInitsTrait) tree match { case tree: ValDef if tree.symbol.exists && tree.symbol.owner.isClass && !tree.symbol.is(Lazy) && !tree.symbol.hasAnnotation(defn.ScalaStaticAnnot) => assert(tree.rhs.isEmpty, i"$tree: initializer should be moved to constructors") @@ -119,7 +119,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase = * constructor. */ private def mightBeDropped(sym: Symbol)(implicit ctx: Context) = - sym.is(Private, butNot = MethodOrLazy) && !sym.is(MutableParamAccessor) + sym.is(Private, butNot = MethodOrLazy) && !sym.isAll(MutableParamAccessor) private final val MutableParamAccessor = allOf(Mutable, ParamAccessor) @@ -275,7 +275,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase = val finalConstrStats = copyParams ::: mappedSuperCalls ::: lazyAssignments ::: stats val expandedConstr = - if (cls.is(NoInitsTrait)) { + if (cls.isAll(NoInitsTrait)) { assert(finalConstrStats.isEmpty) constr } diff --git a/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala b/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala index 741d9aa92719..7c8ae4cd6c8a 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala @@ -58,7 +58,7 @@ class ExpandPrivate extends MiniPhase with IdentityDenotTransformer { thisPhase } private def isVCPrivateParamAccessor(d: SymDenotation)(implicit ctx: Context) = - d.isTerm && d.is(PrivateParamAccessor) && isDerivedValueClass(d.owner) + d.isTerm && d.isAll(PrivateParamAccessor) && isDerivedValueClass(d.owner) /** Make private terms accessed from different classes non-private. * Note: this happens also for accesses between class and linked module class. @@ -105,7 +105,7 @@ class ExpandPrivate extends MiniPhase with IdentityDenotTransformer { thisPhase val sym = tree.symbol tree.rhs match { case Apply(sel @ Select(_: Super, _), _) - if sym.is(PrivateParamAccessor) && sel.symbol.is(ParamAccessor) && sym.name == sel.symbol.name => + if sym.isAll(PrivateParamAccessor) && sel.symbol.is(ParamAccessor) && sym.name == sel.symbol.name => sym.ensureNotPrivate.installAfter(thisPhase) case _ => if (isVCPrivateParamAccessor(sym)) diff --git a/compiler/src/dotty/tools/dotc/transform/Getters.scala b/compiler/src/dotty/tools/dotc/transform/Getters.scala index f635412fae23..e14a7b8779db 100644 --- a/compiler/src/dotty/tools/dotc/transform/Getters.scala +++ b/compiler/src/dotty/tools/dotc/transform/Getters.scala @@ -54,7 +54,7 @@ class Getters extends MiniPhase with SymTransformer { override def transformSym(d: SymDenotation)(implicit ctx: Context): SymDenotation = { def noGetterNeeded = d.is(NoGetterNeeded) || - d.is(PrivateLocal) && !d.owner.is(Trait) && !isDerivedValueClass(d.owner) && !d.is(Flags.Lazy) || + d.isAll(PrivateLocal) && !d.owner.is(Trait) && !isDerivedValueClass(d.owner) && !d.is(Flags.Lazy) || d.is(Module) && d.isStatic || d.hasAnnotation(defn.ScalaStaticAnnot) || d.isSelfSym diff --git a/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala b/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala index a6d8ad4e7506..97c6fad4e0e1 100644 --- a/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala +++ b/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala @@ -88,7 +88,7 @@ class LinkScala2Impls extends MiniPhase with IdentityDenotTransformer { thisPhas private def implMethod(meth: Symbol)(implicit ctx: Context): Symbol = { val implName = ImplMethName(meth.name.asTermName) val cls = meth.owner - if (cls.is(Scala2xTrait)) + if (cls.isAll(Scala2xTrait)) if (meth.isConstructor) cls.info.decl(nme.TRAIT_CONSTRUCTOR).symbol else diff --git a/compiler/src/dotty/tools/dotc/transform/Mixin.scala b/compiler/src/dotty/tools/dotc/transform/Mixin.scala index 125c64f78f15..60f3b60d130d 100644 --- a/compiler/src/dotty/tools/dotc/transform/Mixin.scala +++ b/compiler/src/dotty/tools/dotc/transform/Mixin.scala @@ -196,10 +196,10 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase => def superCallOpt(baseCls: Symbol): List[Tree] = superCalls.get(baseCls) match { case Some(call) => - if (defn.NotRuntimeClasses.contains(baseCls) || baseCls.is(NoInitsTrait)) Nil + if (defn.NotRuntimeClasses.contains(baseCls) || baseCls.isAll(NoInitsTrait)) Nil else call :: Nil case None => - if (baseCls.is(NoInitsTrait) || defn.NoInitClasses.contains(baseCls) || defn.isFunctionClass(baseCls)) Nil + if (baseCls.isAll(NoInitsTrait) || defn.NoInitClasses.contains(baseCls) || defn.isFunctionClass(baseCls)) Nil else { //println(i"synth super call ${baseCls.primaryConstructor}: ${baseCls.primaryConstructor.info}") transformFollowingDeep(superRef(baseCls.primaryConstructor).appliedToNone) :: Nil diff --git a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala index 6eee079dc4f2..50f9b5540428 100644 --- a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala +++ b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala @@ -93,7 +93,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages( tree match { case Quoted(_) | Spliced(_) => tree - case tree: RefTree if tree.symbol.is(InlineParam) => + case tree: RefTree if tree.symbol.isAll(InlineParam) => tree case _: This => assert(checkSymLevel(tree.symbol, tree.tpe, tree.sourcePos).isEmpty) diff --git a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala index 3fbf635642bc..3675d09ce24e 100644 --- a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -310,7 +310,7 @@ object PatternMatcher { lazy val caseAccessors = caseClass.caseAccessors.filter(_.is(Method)) def isSyntheticScala2Unapply(sym: Symbol) = - sym.is(SyntheticCase) && sym.owner.is(Scala2x) + sym.isAll(SyntheticCase) && sym.owner.is(Scala2x) if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length) matchArgsPlan(caseAccessors.map(ref(scrutinee).select(_)), args, onSuccess) diff --git a/compiler/src/dotty/tools/dotc/transform/SelectStatic.scala b/compiler/src/dotty/tools/dotc/transform/SelectStatic.scala index 0203d456b68b..d3f64ee72946 100644 --- a/compiler/src/dotty/tools/dotc/transform/SelectStatic.scala +++ b/compiler/src/dotty/tools/dotc/transform/SelectStatic.scala @@ -28,7 +28,7 @@ class SelectStatic extends MiniPhase with IdentityDenotTransformer { sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot) val isStaticRef = !sym.is(Package) && !sym.maybeOwner.is(Package) && isStaticMember val tree1 = - if (isStaticRef && !tree.qualifier.symbol.is(JavaModule) && !tree.qualifier.isType) + if (isStaticRef && !tree.qualifier.symbol.isAll(JavaModule) && !tree.qualifier.isType) Block(List(tree.qualifier), ref(sym)) else tree diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index 5b97d8df63c3..df2ff38e42d5 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -316,7 +316,7 @@ object Splicer { protected final def interpretTree(tree: Tree)(implicit env: Env): Result = tree match { case Apply(TypeApply(fn, _), quoted :: Nil) if fn.symbol == defn.InternalQuoted_exprQuote => val quoted1 = quoted match { - case quoted: Ident if quoted.symbol.is(InlineByNameProxy) => + case quoted: Ident if quoted.symbol.isAll(InlineByNameProxy) => // inline proxy for by-name parameter quoted.symbol.defTree.asInstanceOf[DefDef].rhs case Inlined(EmptyTree, _, quoted) => quoted diff --git a/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala b/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala index ca91c9df0695..0a9d643a4848 100644 --- a/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala +++ b/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala @@ -100,7 +100,7 @@ class SuperAccessors(thisPhase: DenotTransformer) { assert(sup.symbol.exists, s"missing symbol in $sel: ${sup.tpe}") val clazz = sup.symbol - if (sym.isTerm && !sym.is(Method, butNot = Accessor) && !ctx.owner.is(ParamForwarder)) + if (sym.isTerm && !sym.is(Method, butNot = Accessor) && !ctx.owner.isAll(ParamForwarder)) // ParamForwaders as installed ParamForwarding.scala do use super calls to vals ctx.error(s"super may be not be used on ${sym.underlyingSymbol}", sel.sourcePos) else if (isDisallowed(sym)) diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index 89b1af7c6a35..7c8fda62a03d 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -185,7 +185,7 @@ class TreeChecker extends Phase with SymTransformer { /** assert Java classes are not used as objects */ def assertIdentNotJavaClass(tree: Tree)(implicit ctx: Context): Unit = tree match { case _ : untpd.Ident => - assert(!tree.symbol.is(JavaModule), "Java class can't be used as value: " + tree) + assert(!tree.symbol.isAll(JavaModule), "Java class can't be used as value: " + tree) case _ => } diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 094770667327..fb3f0c973274 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -424,7 +424,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { lazy val caseAccessors = caseClass.caseAccessors.filter(_.is(Method)) def isSyntheticScala2Unapply(sym: Symbol) = - sym.is(SyntheticCase) && sym.owner.is(Scala2x) + sym.isAll(SyntheticCase) && sym.owner.is(Scala2x) val mt @ MethodType(_) = unapp.widen @@ -494,7 +494,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { ) case tp if tp.isRef(defn.UnitClass) => Typ(ConstantType(Constant(())), true) :: Nil - case tp if tp.classSymbol.is(JavaEnum) => + case tp if tp.classSymbol.isAll(JavaEnum) => children.map(sym => Typ(sym.termRef, true)) case tp => val parts = children.map { sym => @@ -535,7 +535,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { }) || tp.isRef(defn.BooleanClass) || tp.isRef(defn.UnitClass) || - tp.classSymbol.is(JavaEnumTrait) + tp.classSymbol.isAll(JavaEnumTrait) debug.println(s"decomposable: ${tp.show} = $res") @@ -681,7 +681,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { isCheckable(and.tp1) || isCheckable(and.tp2) }) || tpw.isRef(defn.BooleanClass) || - tpw.typeSymbol.is(JavaEnum) || + tpw.typeSymbol.isAll(JavaEnum) || (defn.isTupleType(tpw) && tpw.argInfos.exists(isCheckable(_))) } diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 2d4d611843af..418c7dafd516 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1370,7 +1370,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => case pt: PolyType => pt.derivedLambdaType(pt.paramNames, pt.paramInfos, widenImplied(pt.resultType, alt)) case _ => - if (alt.symbol.is(SyntheticImpliedMethod)) tp.widenToParents + if (alt.symbol.isAll(SyntheticImpliedMethod)) tp.widenToParents else tp } diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 736a3498faa7..2e240c3ebc95 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -392,7 +392,7 @@ object Checking { if (sym.is(flag)) fail(AbstractMemberMayNotHaveModifier(sym, flag)) def checkNoConflict(flag1: FlagSet, flag2: FlagSet, msg: => String) = - if (sym.is(allOf(flag1, flag2))) fail(msg) + if (sym.isAll(allOf(flag1, flag2))) fail(msg) def checkCombination(flag1: FlagSet, flag2: FlagSet) = checkNoConflict(flag1, flag2, i"illegal combination of modifiers: `$flag1` and `$flag2` for: $sym") def checkApplicable(flag: FlagSet, ok: Boolean) = @@ -600,7 +600,7 @@ trait Checking { val sym = tree.tpe.termSymbol // The check is avoided inside Java compilation units because it always fails // on the singleton type Module.type. - if ((sym is Package) || ((sym is JavaModule) && !ctx.compilationUnit.isJava)) ctx.error(JavaSymbolIsNotAValue(sym), tree.sourcePos) + if ((sym is Package) || (sym.isAll(JavaModule) && !ctx.compilationUnit.isJava)) ctx.error(JavaSymbolIsNotAValue(sym), tree.sourcePos) } tree } diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 6e61baaad096..02d915c16854 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -258,7 +258,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { var inlineFlag = InlineProxy if (paramtp.hasAnnotation(defn.InlineParamAnnot)) inlineFlag |= Inline val (bindingFlags, bindingType) = - if (isByName) (InlineByNameProxy.toTermFlags, ExprType(argtpe.widen)) + if (isByName) (InlineByNameProxy.toFlags.toTermFlags, ExprType(argtpe.widen)) else (inlineFlag, argtpe.widen) val boundSym = newSym(name, bindingFlags, bindingType).asTerm val binding = { @@ -1149,7 +1149,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { case Some(x) => x > 1 || x == 1 && !boundSym.is(Method) case none => true } - } && !(boundSym.is(InlineMethod) && boundSym.is(ImplicitOrImplied)) + } && !(boundSym.isAll(InlineMethod) && boundSym.is(ImplicitOrImplied)) val inlineBindings = new TreeMap { override def transform(t: Tree)(implicit ctx: Context) = t match { diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index e45416e18fa9..36321e51f8a4 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -503,7 +503,7 @@ class Namer { typer: Typer => /** Determines whether this field holds an enum constant. */ def isEnumConstant(vd: ValDef)(implicit ctx: Context): Boolean = - vd.mods.is(JavaEnumValue) + vd.mods.isAll(JavaEnumValue) /** Add child annotation for `child` to annotations of `cls`. The annotation * is added at the correct insertion point, so that Child annotations appear @@ -532,7 +532,7 @@ class Namer { typer: Typer => def addEnumConstants(mdef: DefTree, sym: Symbol)(implicit ctx: Context): Unit = mdef match { case vdef: ValDef if (isEnumConstant(vdef)) => val enumClass = sym.owner.linkedClass - if (!(enumClass is Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed) + if (!(enumClass is Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed.toFlags) addChild(enumClass, sym) case _ => } diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index bd0ccac499dc..dc26d3351b27 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -335,7 +335,7 @@ object RefChecks { (member.flags & AccessFlags).isEmpty // member is public || // - or - (!other.is(Protected) || member.is(Protected)) && // if o is protected, so is m, and - (ob.isContainedIn(mb) || other.is(JavaProtected)) // m relaxes o's access boundary, + (ob.isContainedIn(mb) || other.isAll(JavaProtected)) // m relaxes o's access boundary, // or o is Java defined and protected (see #3946) ) if (!isOverrideAccessOK) { @@ -356,7 +356,7 @@ object RefChecks { // Also exclusion for implicit shortcut methods // Also excluded under Scala2 mode are overrides of default methods of Java traits. if (autoOverride(member) || - other.owner.is(JavaTrait) && + other.owner.isAll(JavaTrait) && ctx.testScala2Mode("`override' modifier required when a Java 8 default method is re-implemented", member.sourcePos)) member.setFlag(Override) else if (member.isType && self.memberInfo(member) =:= self.memberInfo(other)) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 547f132d2066..2b9dcc6741c4 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2772,7 +2772,7 @@ class Typer extends Namer // - the current tree is a synthetic apply which is not expandable (eta-expasion would simply undo that) if (arity >= 0 && !tree.symbol.isConstructor && - !tree.symbol.is(InlineMethod) && + !tree.symbol.isAll(InlineMethod) && !ctx.mode.is(Mode.Pattern) && !(isSyntheticApply(tree) && !isExpandableApply)) { if (!defn.isFunctionType(pt)) diff --git a/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala b/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala index d76800241b8f..8adc740c70f0 100644 --- a/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala +++ b/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala @@ -87,7 +87,7 @@ class VarianceChecker()(implicit ctx: Context) { def ignoreVarianceIn(base: Symbol): Boolean = ( base.isTerm || base.is(Package) - || base.is(PrivateLocal) + || base.isAll(PrivateLocal) ) /** The variance of a symbol occurrence of `tvar` seen at the level of the definition of `base`. @@ -175,7 +175,7 @@ class VarianceChecker()(implicit ctx: Context) { case Some(VarianceError(tvar, required)) => def msg = i"${varianceString(tvar.flags)} $tvar occurs in ${varianceString(required)} position in type ${sym.info} of $sym" if (ctx.scala2Mode && - (sym.owner.isConstructor || sym.ownersIterator.exists(_.is(ProtectedLocal)))) { + (sym.owner.isConstructor || sym.ownersIterator.exists(_.isAll(ProtectedLocal)))) { ctx.migrationWarning( s"According to new variance rules, this is no longer accepted; need to annotate with @uncheckedVariance:\n$msg", pos) @@ -193,7 +193,7 @@ class VarianceChecker()(implicit ctx: Context) { // No variance check for private/protected[this] methods/values. def skip = !sym.exists || - sym.is(PrivateLocal) || + sym.isAll(PrivateLocal) || sym.name.is(InlineAccessorName) || // TODO: should we exclude all synthetic members? sym.is(TypeParam) && sym.owner.isClass // already taken care of in primary constructor of class try tree match { From 818225ecfbc374307a5ba55e6aa3d650981dd689 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 24 May 2019 19:12:12 +0200 Subject: [PATCH 03/25] Use isOneOf for checking flag sets with more than one member --- .../backend/jvm/DottyBackendInterface.scala | 56 ++++---- .../dotty/tools/backend/sjs/JSCodeGen.scala | 2 +- .../backend/sjs/JUnitBootstrappers.scala | 2 +- .../src/dotty/tools/dotc/ast/Desugar.scala | 28 ++-- .../src/dotty/tools/dotc/ast/TreeInfo.scala | 8 +- compiler/src/dotty/tools/dotc/ast/Trees.scala | 4 +- compiler/src/dotty/tools/dotc/ast/tpd.scala | 8 +- compiler/src/dotty/tools/dotc/ast/untpd.scala | 6 +- .../tools/dotc/core/CheckRealizable.scala | 6 +- .../dotty/tools/dotc/core/Definitions.scala | 4 +- .../dotty/tools/dotc/core/Denotations.scala | 8 +- .../src/dotty/tools/dotc/core/Flags.scala | 18 ++- .../src/dotty/tools/dotc/core/NameOps.scala | 2 +- .../src/dotty/tools/dotc/core/Scopes.scala | 2 +- .../tools/dotc/core/SymDenotations.scala | 122 ++++++++++-------- .../dotty/tools/dotc/core/SymbolLoaders.scala | 4 +- .../src/dotty/tools/dotc/core/Symbols.scala | 18 +-- .../dotty/tools/dotc/core/TypeComparer.scala | 2 +- .../dotty/tools/dotc/core/TypeErasure.scala | 10 +- .../dotty/tools/dotc/core/TypeErrors.scala | 2 +- .../src/dotty/tools/dotc/core/TypeOps.scala | 4 +- .../src/dotty/tools/dotc/core/Types.scala | 16 +-- .../dotc/core/classfile/ClassfileParser.scala | 14 +- .../tools/dotc/core/tasty/TreePickler.scala | 72 +++++------ .../tools/dotc/core/tasty/TreeUnpickler.scala | 8 +- .../core/unpickleScala2/Scala2Unpickler.scala | 32 ++--- .../tools/dotc/interactive/Interactive.scala | 2 +- .../tools/dotc/parsing/JavaParsers.scala | 12 +- .../dotty/tools/dotc/parsing/Parsers.scala | 20 +-- .../dotc/printing/DecompilerPrinter.scala | 2 +- .../tools/dotc/printing/PlainPrinter.scala | 30 ++--- .../tools/dotc/printing/RefinedPrinter.scala | 28 ++-- .../dotc/reporting/diagnostic/messages.scala | 2 +- .../src/dotty/tools/dotc/sbt/ExtractAPI.scala | 4 +- .../tools/dotc/tastyreflect/KernelImpl.scala | 2 +- .../dotty/tools/dotc/transform/Bridges.scala | 2 +- .../tools/dotc/transform/CheckReentrant.scala | 2 +- .../tools/dotc/transform/Constructors.scala | 4 +- .../dotc/transform/ElimErasedValueType.scala | 2 +- .../tools/dotc/transform/ElimRepeated.scala | 4 +- .../dotty/tools/dotc/transform/Erasure.scala | 6 +- .../tools/dotc/transform/ExpandPrivate.scala | 2 +- .../tools/dotc/transform/ExplicitOuter.scala | 10 +- .../dotc/transform/ExtensionMethods.scala | 4 +- .../tools/dotc/transform/FirstTransform.scala | 2 +- .../dotty/tools/dotc/transform/Flatten.scala | 4 +- .../dotty/tools/dotc/transform/Getters.scala | 10 +- .../dotty/tools/dotc/transform/LazyVals.scala | 4 +- .../tools/dotc/transform/MacroTransform.scala | 2 +- .../tools/dotc/transform/MegaPhase.scala | 2 +- .../dotty/tools/dotc/transform/Memoize.scala | 2 +- .../dotty/tools/dotc/transform/Mixin.scala | 20 +-- .../dotty/tools/dotc/transform/MixinOps.scala | 2 +- .../dotc/transform/ParamForwarding.scala | 2 +- .../dotty/tools/dotc/transform/Pickler.scala | 2 +- .../tools/dotc/transform/PostTyper.scala | 2 +- .../tools/dotc/transform/RenameLifted.scala | 2 +- .../tools/dotc/transform/SuperAccessors.scala | 16 +-- .../dotty/tools/dotc/transform/SymUtils.scala | 6 +- .../dotc/transform/TransformByNameApply.scala | 2 +- .../tools/dotc/transform/TreeChecker.scala | 6 +- .../tools/dotc/transform/patmat/Space.scala | 2 +- .../dotty/tools/dotc/typer/Applications.scala | 6 +- .../src/dotty/tools/dotc/typer/Checking.scala | 28 ++-- .../dotty/tools/dotc/typer/ImportInfo.scala | 6 +- .../src/dotty/tools/dotc/typer/Inliner.scala | 2 +- .../src/dotty/tools/dotc/typer/Namer.scala | 38 +++--- .../tools/dotc/typer/PrepareInlineable.scala | 2 +- .../dotty/tools/dotc/typer/RefChecks.scala | 14 +- .../dotty/tools/dotc/typer/TypeAssigner.scala | 6 +- .../src/dotty/tools/dotc/typer/Typer.scala | 20 +-- .../tools/dotc/typer/VarianceChecker.scala | 4 +- .../src/dotty/tools/repl/ReplDriver.scala | 2 +- .../tools/dottydoc/core/DocASTPhase.scala | 4 +- .../dottydoc/core/DocImplicitsPhase.scala | 2 +- 75 files changed, 419 insertions(+), 399 deletions(-) diff --git a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index 7fe2743e0d16..2f92e738f838 100644 --- a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -658,50 +658,50 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma def isConstructor: Boolean = toDenot(sym).isConstructor def isExpanded: Boolean = sym.name.is(ExpandedName) def isAnonymousFunction: Boolean = toDenot(sym).isAnonymousFunction - def isMethod: Boolean = sym is Flags.Method - def isPublic: Boolean = sym.flags.is(Flags.EmptyFlags, Flags.Private | Flags.Protected) - def isSynthetic: Boolean = sym is Flags.Synthetic - def isPackageClass: Boolean = sym is Flags.PackageClass - def isModuleClass: Boolean = sym is Flags.ModuleClass - def isModule: Boolean = sym is Flags.Module + def isMethod: Boolean = sym.is(Flags.Method) + def isPublic: Boolean = !sym.flags.is(Flags.Private | Flags.Protected) + def isSynthetic: Boolean = sym.is(Flags.Synthetic) + def isPackageClass: Boolean = sym.is(Flags.PackageClass) + def isModuleClass: Boolean = sym.is(Flags.ModuleClass) + def isModule: Boolean = sym.is(Flags.Module) def isStrictFP: Boolean = false // todo: implement - def isLabel: Boolean = sym is Flags.Label - def hasPackageFlag: Boolean = sym is Flags.Package - def isInterface: Boolean = (sym is Flags.PureInterface) || (sym is Flags.Trait) + def isLabel: Boolean = sym.is(Flags.Label) + def hasPackageFlag: Boolean = sym.is(Flags.Package) + def isInterface: Boolean = (sym.is(Flags.PureInterface)) || (sym.is(Flags.Trait)) def isGetter: Boolean = toDenot(sym).isGetter def isSetter: Boolean = toDenot(sym).isSetter def isGetClass: Boolean = sym eq defn.Any_getClass - def isJavaDefined: Boolean = sym is Flags.JavaDefined - def isJavaDefaultMethod: Boolean = !((sym is Flags.Deferred) || toDenot(sym).isClassConstructor) - def isDeferred: Boolean = sym is Flags.Deferred - def isPrivate: Boolean = sym is Flags.Private + def isJavaDefined: Boolean = sym.is(Flags.JavaDefined) + def isJavaDefaultMethod: Boolean = !((sym.is(Flags.Deferred)) || toDenot(sym).isClassConstructor) + def isDeferred: Boolean = sym.is(Flags.Deferred) + def isPrivate: Boolean = sym.is(Flags.Private) def getsJavaFinalFlag: Boolean = - isFinal && !toDenot(sym).isClassConstructor && !(sym is Flags.Mutable) && !(sym.enclosingClass is Flags.Trait) + isFinal && !toDenot(sym).isClassConstructor && !(sym.is(Flags.Mutable)) && !(sym.enclosingClass.is(Flags.Trait)) def getsJavaPrivateFlag: Boolean = isPrivate //|| (sym.isPrimaryConstructor && sym.owner.isTopLevelModuleClass) - def isFinal: Boolean = sym is Flags.Final + def isFinal: Boolean = sym.is(Flags.Final) def isStaticMember: Boolean = (sym ne NoSymbol) && - ((sym is Flags.JavaStatic) || toDenot(sym).hasAnnotation(ctx.definitions.ScalaStaticAnnot)) + ((sym.is(Flags.JavaStatic)) || toDenot(sym).hasAnnotation(ctx.definitions.ScalaStaticAnnot)) // guard against no sumbol cause this code is executed to select which call type(static\dynamic) to use to call array.clone def isBottomClass: Boolean = (sym ne defn.NullClass) && (sym ne defn.NothingClass) - def isBridge: Boolean = sym is Flags.Bridge - def isArtifact: Boolean = sym is Flags.Artifact + def isBridge: Boolean = sym.is(Flags.Bridge) + def isArtifact: Boolean = sym.is(Flags.Artifact) def hasEnumFlag: Boolean = sym.isAll(Flags.JavaEnum) def hasAccessBoundary: Boolean = sym.accessBoundary(defn.RootClass) ne defn.RootClass - def isVarargsMethod: Boolean = sym is Flags.JavaVarargs + def isVarargsMethod: Boolean = sym.is(Flags.JavaVarargs) def isDeprecated: Boolean = false - def isMutable: Boolean = sym is Flags.Mutable + def isMutable: Boolean = sym.is(Flags.Mutable) def hasAbstractFlag: Boolean = - (sym is Flags.Abstract) || (sym.isAll(Flags.JavaInterface)) || (sym is Flags.Trait) - def hasModuleFlag: Boolean = sym is Flags.Module - def isSynchronized: Boolean = sym is Flags.Synchronized + (sym.is(Flags.Abstract)) || (sym.isAll(Flags.JavaInterface)) || (sym.is(Flags.Trait)) + def hasModuleFlag: Boolean = sym.is(Flags.Module) + def isSynchronized: Boolean = sym.is(Flags.Synchronized) def isNonBottomSubClass(other: Symbol): Boolean = sym.derivesFrom(other) def hasAnnotation(ann: Symbol): Boolean = toDenot(sym).hasAnnotation(ann) def shouldEmitForwarders: Boolean = - (sym is Flags.Module) && sym.isStatic + (sym.is(Flags.Module)) && sym.isStatic def isJavaEntryPoint: Boolean = CollectEntryPoints.isJavaEntryPoint(sym) def isEnum = sym.is(Flags.Enum) @@ -713,7 +713,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma * for such objects will get a MODULE$ flag and a corresponding static initializer. */ def isStaticModuleClass: Boolean = - (sym is Flags.Module) && { + (sym.is(Flags.Module)) && { // scalac uses atPickling here // this would not work if modules are created after pickling // for example by specialization @@ -736,7 +736,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma def superClass: Symbol = { val t = toDenot(sym).asClass.superClass if (t.exists) t - else if (sym is Flags.ModuleClass) { + else if (sym.is(Flags.ModuleClass)) { // workaround #371 println(s"Warning: mocking up superclass for $sym") @@ -749,7 +749,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma def linkedClass: Symbol = toDenot(sym)(ctx).linkedClass(ctx) //exitingPickler(sym.linkedClassOfClass) def companionClass: Symbol = toDenot(sym).companionClass def companionModule: Symbol = toDenot(sym).companionModule - def companionSymbol: Symbol = if (sym is Flags.Module) companionClass else companionModule + def companionSymbol: Symbol = if (sym.is(Flags.Module)) companionClass else companionModule def moduleClass: Symbol = toDenot(sym).moduleClass def enclosingClassSym: Symbol = { if (this.isClass) { @@ -859,7 +859,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma implicit def typeHelper(tp: Type): TypeHelper = new TypeHelper { def member(string: Name): Symbol = tp.member(string.toTermName).symbol - def isFinalType: Boolean = tp.typeSymbol is Flags.Final //in scalac checks for type parameters. Why? Aren't they gone by backend? + def isFinalType: Boolean = tp.typeSymbol.is(Flags.Final) //in scalac checks for type parameters. Why? Aren't they gone by backend? def underlying: Type = tp match { case t: TypeProxy => t.underlying diff --git a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala index 7dccc47d304a..1ae478c0aa95 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala @@ -540,7 +540,7 @@ class JSCodeGen()(implicit ctx: Context) { implicit pos: SourcePosition): Option[js.Tree] = { val ctors = if (sym.is(Abstract)) Nil - else sym.info.member(nme.CONSTRUCTOR).alternatives.map(_.symbol).filter(m => !m.is(Private | Protected)) + else sym.info.member(nme.CONSTRUCTOR).alternatives.map(_.symbol).filter(m => !m.isOneOf(Private | Protected)) if (ctors.isEmpty) { None diff --git a/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala b/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala index 7c6ced8b19d2..d1a3139a3067 100644 --- a/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala +++ b/compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala @@ -128,7 +128,7 @@ class JUnitBootstrappers extends MiniPhase { def isTestClass(sym: Symbol): Boolean = { sym.isClass && - !sym.is(ModuleClass | Abstract | Trait) && + !sym.isOneOf(ModuleClass | Abstract | Trait) && hasTests(sym.asClass) } diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 62a87138d57a..8e22501699df 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -90,10 +90,10 @@ object desugar { * in apply/unapply methods. */ override def ensureCompletions(implicit ctx: Context): Unit = - if (!(ctx.owner is Package)) + if (!ctx.owner.is(Package)) if (ctx.owner.isClass) { ctx.owner.ensureCompleted() - if (ctx.owner is ModuleClass) + if (ctx.owner.is(ModuleClass)) ctx.owner.linkedClass.ensureCompleted() } else ensureCompletions(ctx.outer) @@ -159,7 +159,7 @@ object desugar { val vdef @ ValDef(name, tpt, rhs) = transformQuotedPatternName(vdef0) val mods = vdef.mods val setterNeeded = - (mods is Mutable) && ctx.owner.isClass && (!mods.isAll(PrivateLocal) || (ctx.owner is Trait)) + mods.is(Mutable) && ctx.owner.isClass && (!mods.isAll(PrivateLocal) || ctx.owner.is(Trait)) if (setterNeeded) { // TODO: copy of vdef as getter needed? // val getter = ValDef(mods, name, tpt, rhs) withPos vdef.pos? @@ -323,7 +323,7 @@ object desugar { meth case evidenceParams => val vparamss1 = meth.vparamss.reverse match { - case (vparams @ (vparam :: _)) :: rvparamss if vparam.mods is ImplicitOrGiven => + case (vparams @ (vparam :: _)) :: rvparamss if vparam.mods.isOneOf(ImplicitOrGiven) => ((evidenceParams ++ vparams) :: rvparamss).reverse case _ => meth.vparamss :+ evidenceParams @@ -334,7 +334,7 @@ object desugar { /** The implicit evidence parameters of `meth`, as generated by `desugar.defDef` */ private def evidenceParams(meth: DefDef)(implicit ctx: Context): List[ValDef] = meth.vparamss.reverse match { - case (vparams @ (vparam :: _)) :: _ if vparam.mods is ImplicitOrGiven => + case (vparams @ (vparam :: _)) :: _ if vparam.mods.isOneOf(ImplicitOrGiven) => vparams.dropWhile(!_.name.is(EvidenceParamName)) case _ => Nil @@ -413,7 +413,7 @@ object desugar { if (isCaseClass && originalTparams.isEmpty) ctx.error(CaseClassMissingParamList(cdef), namePos) ListOfNil - } else if (isCaseClass && originalVparamss.head.exists(_.mods.is(ImplicitOrGiven))) { + } else if (isCaseClass && originalVparamss.head.exists(_.mods.isOneOf(ImplicitOrGiven))) { ctx.error("Case classes should have a non-implicit parameter list", namePos) ListOfNil } @@ -508,7 +508,7 @@ object desugar { // new C[Ts](paramss) lazy val creatorExpr = { val vparamss = constrVparamss match { - case (vparam :: _) :: _ if vparam.mods.is(ImplicitOrGiven) => // add a leading () to match class parameters + case (vparam :: _) :: _ if vparam.mods.isOneOf(ImplicitOrGiven) => // add a leading () to match class parameters Nil :: constrVparamss case _ => constrVparamss @@ -658,7 +658,7 @@ object desugar { def widenedCreatorExpr = (creatorExpr /: widenDefs)((rhs, meth) => Apply(Ident(meth.name), rhs :: Nil)) val applyMeths = - if (mods is Abstract) Nil + if (mods.is(Abstract)) Nil else { val copiedFlagsMask = DefaultParameterized | (copiedAccessFlags & Private) val appMods = { @@ -703,9 +703,9 @@ object desugar { // synthetic implicit C[Ts](p11: T11, ..., p1N: T1N) ... (pM1: TM1, ..., pMN: TMN): C[Ts] = // new C[Ts](p11, ..., p1N) ... (pM1, ..., pMN) = val implicitWrappers = - if (!mods.is(ImplicitOrImplied)) + if (!mods.isOneOf(ImplicitOrImplied)) Nil - else if (ctx.owner is Package) { + else if (ctx.owner.is(Package)) { ctx.error(TopLevelImplicitClass(cdef), cdef.sourcePos) Nil } @@ -792,7 +792,7 @@ object desugar { if (mods.is(Final) && !mods.is(Synthetic)) ctx.warning(em"${hl("final")} modifier is redundant for objects", flagSourcePos(Final)) - if (mods is Package) + if (mods.is(Package)) PackageDef(Ident(moduleName), cpy.ModuleDef(mdef)(nme.PACKAGE, impl).withMods(mods &~ Package) :: Nil) else if (isEnumCase) { typeParamIsReferenced(enumClass.typeParams, Nil, Nil, impl.parents) @@ -982,7 +982,7 @@ object desugar { val restDefs = for (((named, tpt), n) <- vars.zipWithIndex if named.name != nme.WILDCARD) yield - if (mods is Lazy) derivedDefDef(original, named, tpt, selector(n), mods &~ Lazy) + if (mods.is(Lazy)) derivedDefDef(original, named, tpt, selector(n), mods &~ Lazy) else derivedValDef(original, named, tpt, selector(n), mods) flatTree(firstDef :: restDefs) } @@ -1109,8 +1109,8 @@ object desugar { def needsObject(stat: Tree) = stat match { case _: ValDef | _: PatDef | _: DefDef | _: Export => true case stat: ModuleDef => - stat.mods.is(ImplicitOrImplied) || opaqueNames.contains(stat.name.stripModuleClassSuffix.toTypeName) - case stat: TypeDef => !stat.isClassDef || stat.mods.is(ImplicitOrImplied) + stat.mods.isOneOf(ImplicitOrImplied) || opaqueNames.contains(stat.name.stripModuleClassSuffix.toTypeName) + case stat: TypeDef => !stat.isClassDef || stat.mods.isOneOf(ImplicitOrImplied) case _ => false } val (nestedStats, topStats) = pdef.stats.partition(needsObject) diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index b11ac626f767..64c971698b97 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -296,7 +296,7 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped] */ def lacksDefinition(mdef: MemberDef)(implicit ctx: Context): Boolean = mdef match { case mdef: ValOrDefDef => - mdef.unforcedRhs == EmptyTree && !mdef.name.isConstructorName && !mdef.mods.is(TermParamOrAccessor) + mdef.unforcedRhs == EmptyTree && !mdef.name.isConstructorName && !mdef.mods.isOneOf(TermParamOrAccessor) case mdef: TypeDef => def isBounds(rhs: Tree): Boolean = rhs match { case _: TypeBoundsTree => true @@ -534,7 +534,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => */ def isVariableOrGetter(tree: Tree)(implicit ctx: Context): Boolean = { def sym = tree.symbol - def isVar = sym is Mutable + def isVar = sym.is(Mutable) def isGetter = mayBeVarGetter(sym) && sym.owner.info.member(sym.name.asTermName.setterName).exists @@ -661,7 +661,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => private def isSimpleThrowable(tp: Type)(implicit ctx: Context): Boolean = tp match { case tp @ TypeRef(pre, _) => (pre == NoPrefix || pre.widen.typeSymbol.isStatic) && - (tp.symbol derivesFrom defn.ThrowableClass) && !(tp.symbol is Trait) + (tp.symbol derivesFrom defn.ThrowableClass) && !tp.symbol.is(Trait) case _ => false } @@ -719,7 +719,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => else Nil case vdef: ValDef => val sym = vdef.symbol - assert(sym is Module) + assert(sym.is(Module)) if (cls == sym.companionClass || cls == sym.moduleClass) vdef :: Nil else Nil case tree => diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index 9763884684bd..330edc6005ed 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -410,7 +410,7 @@ object Trees { // Denotation of a This tree is always the underlying class; needs correction for modules. override def denot(implicit ctx: Context): Denotation = { typeOpt match { - case tpe @ TermRef(pre, _) if tpe.symbol is Module => + case tpe @ TermRef(pre, _) if tpe.symbol.is(Module) => tpe.symbol.moduleClass.denot.asSeenFrom(pre) case _ => super.denot @@ -750,7 +750,7 @@ object Trees { def unforced: LazyTree = preRhs protected def force(x: AnyRef): Unit = preRhs = x - override def disableOverlapChecks = rawMods.is(Flags.Implied) + override def disableOverlapChecks = rawMods.is(Implied) // disable order checks for implicit aliases since their given clause follows // their for clause, but the two appear swapped in the DefDef. } diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 7b70bf2591a0..001e532027c5 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -268,7 +268,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def ClassDef(cls: ClassSymbol, constr: DefDef, body: List[Tree], superArgs: List[Tree] = Nil)(implicit ctx: Context): TypeDef = { val firstParent :: otherParents = cls.info.parents val superRef = - if (cls is Trait) TypeTree(firstParent) + if (cls.is(Trait)) TypeTree(firstParent) else { def isApplicable(ctpe: Type): Boolean = ctpe match { case ctpe: PolyType => @@ -289,7 +289,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { if (cls.classInfo.selfInfo ne NoType) ValDef(ctx.newSelfSym(cls)) else EmptyValDef def isOwnTypeParam(stat: Tree) = - (stat.symbol is TypeParam) && stat.symbol.owner == cls + (stat.symbol.is(TypeParam)) && stat.symbol.owner == cls val bodyTypeParams = body filter isOwnTypeParam map (_.symbol) val newTypeParams = for (tparam <- cls.typeParams if !(bodyTypeParams contains tparam)) @@ -964,7 +964,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { */ def becomes(rhs: Tree)(implicit ctx: Context): Tree = { val sym = tree.symbol - if (sym is Method) { + if (sym.is(Method)) { val setter = sym.setter.orElse { assert(sym.name.isSetterName && sym.info.firstParamTypes.nonEmpty) sym @@ -1002,7 +1002,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { * Returns true if the symbol is a val or def generated by eta-expansion/inline */ override protected def skipLocal(sym: Symbol): Boolean = - sym.is(InlineProxy) || sym.is(Synthetic) + sym.isOneOf(InlineProxy | Synthetic) } mapToUnderlying.transform(tree) } diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index 9deb73b54621..7eb98aafef75 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -183,8 +183,10 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { annotations: List[Tree] = Nil, mods: List[Mod] = Nil) { - def is(fs: FlagSet): Boolean = flags is fs + def is(fs: FlagSet): Boolean = flags.is(fs) def is(fs: FlagSet, butNot: FlagSet): Boolean = flags.is(fs, butNot = butNot) + def isOneOf(fs: FlagSet): Boolean = flags.isOneOf(fs) + def isOneOf(fs: FlagSet, butNot: FlagSet): Boolean = flags.isOneOf(fs, butNot = butNot) def isAll(fc: FlagConjunction): Boolean = flags.isAll(fc) def | (fs: FlagSet): Modifiers = withFlags(flags | fs) @@ -215,7 +217,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { else { if (ms.nonEmpty) for (m <- ms) - assert(flags.is(m.flags) || + assert(flags.isAll(allOf(m.flags)) || m.isInstanceOf[Mod.Private] && !privateWithin.isEmpty, s"unaccounted modifier: $m in $this when adding $ms") copy(mods = ms) diff --git a/compiler/src/dotty/tools/dotc/core/CheckRealizable.scala b/compiler/src/dotty/tools/dotc/core/CheckRealizable.scala index e4849bdf1c25..0823fbbd2746 100644 --- a/compiler/src/dotty/tools/dotc/core/CheckRealizable.scala +++ b/compiler/src/dotty/tools/dotc/core/CheckRealizable.scala @@ -47,7 +47,7 @@ object CheckRealizable { def boundsRealizability(tp: Type)(implicit ctx: Context): Realizability = new CheckRealizable().boundsRealizability(tp) - private val LateInitialized = Lazy | Erased + private val LateInitializedFlags = Lazy | Erased } /** Compute realizability status. @@ -70,7 +70,7 @@ class CheckRealizable(implicit ctx: Context) { /** Is symbol's definitition a lazy or erased val? * (note we exclude modules here, because their realizability is ensured separately) */ - private def isLateInitialized(sym: Symbol) = sym.is(LateInitialized, butNot = Module) + private def isLateInitialized(sym: Symbol) = sym.isOneOf(LateInitializedFlags, butNot = Module) /** The realizability status of given type `tp`*/ def realizability(tp: Type): Realizability = tp.dealias match { @@ -183,7 +183,7 @@ class CheckRealizable(implicit ctx: Context) { private def memberRealizability(tp: Type) = { def checkField(sofar: Realizability, fld: SingleDenotation): Realizability = sofar andAlso { - if (checkedFields.contains(fld.symbol) || fld.symbol.is(Private | Mutable | LateInitialized)) + if (checkedFields.contains(fld.symbol) || fld.symbol.isOneOf(Private | Mutable | LateInitializedFlags)) // if field is private it cannot be part of a visible path // if field is mutable it cannot be part of a path // if field is lazy or erased it does not need to be initialized when the owning object is diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 194a418abb53..57098a0c89cf 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -520,10 +520,10 @@ class Definitions { @threadUnsafe lazy val LongType: TypeRef = valueTypeRef("scala.Long", java.lang.Long.TYPE, LongEnc, nme.specializedTypeNames.Long) def LongClass(implicit ctx: Context): ClassSymbol = LongType.symbol.asClass @threadUnsafe lazy val Long_XOR_Long: Symbol = LongType.member(nme.XOR).requiredSymbol("method", nme.XOR, LongType.denot)( - x => (x is Method) && (x.info.firstParamTypes.head isRef defn.LongClass) + x => x.is(Method) && (x.info.firstParamTypes.head isRef defn.LongClass) ) @threadUnsafe lazy val Long_LSR_Int: Symbol = LongType.member(nme.LSR).requiredSymbol("method", nme.LSR, LongType.denot)( - x => (x is Method) && (x.info.firstParamTypes.head isRef defn.IntClass) + x => x.is(Method) && (x.info.firstParamTypes.head isRef defn.IntClass) ) @threadUnsafe lazy val Long_plusR: TermRef = LongClass.requiredMethodRef(nme.PLUS, List(LongType)) def Long_+ : Symbol = Long_plusR.symbol diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index ec2e166c750a..87b0a3d08765 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -305,7 +305,7 @@ object Denotations { def requiredMethod(pname: PreName)(implicit ctx: Context): TermSymbol = { val name = pname.toTermName - info.member(name).requiredSymbol("method", name, this)(_ is Method).asTerm + info.member(name).requiredSymbol("method", name, this)(_.is(Method)).asTerm } def requiredMethodRef(name: PreName)(implicit ctx: Context): TermRef = requiredMethod(name).termRef @@ -313,7 +313,7 @@ object Denotations { def requiredMethod(pname: PreName, argTypes: List[Type])(implicit ctx: Context): TermSymbol = { val name = pname.toTermName info.member(name).requiredSymbol(i"method", name, this, argTypes) { x => - (x is Method) && { + (x.is(Method)) && { x.info.paramInfoss match { case paramInfos :: Nil => paramInfos.corresponds(argTypes)(_ =:= _) case _ => false @@ -1152,7 +1152,7 @@ object Denotations { case symd: SymDenotation => symd case _ => symbol.denot } - symd.isAll(required) && !symd.is(excluded) + symd.isAll(required) && !symd.isOneOf(excluded) } } @@ -1370,7 +1370,7 @@ object Denotations { * enter it. */ def missingHook(owner: Symbol, name: Name)(implicit ctx: Context): Symbol = - if ((owner is Package) && name.isTermName) + if ((owner.is(Package)) && name.isTermName) ctx.newCompletePackageSymbol(owner, name.asTermName).entered else NoSymbol diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index f65c8d5b716c..c36c4e27f621 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -44,6 +44,7 @@ object Flags { * This means that both the kind flags and the carrier bits have non-empty intersection. */ def is(flags: FlagSet): Boolean = { + assert(flags.numFlags == 1) val fs = bits & flags.bits (fs & KINDFLAGS) != 0 && (fs & ~KINDFLAGS) != 0 } @@ -51,7 +52,14 @@ object Flags { /** Does this flag set have a non-empty intersection with the given flag set, * and at the same time contain none of the flags in the `butNot` set? */ - def is(flags: FlagSet, butNot: FlagSet): Boolean = is(flags) && !is(butNot) + def is(flags: FlagSet, butNot: FlagSet): Boolean = is(flags) && !isOneOf(butNot) + + def isOneOf(flags: FlagSet): Boolean = { + val fs = bits & flags.bits + (fs & KINDFLAGS) != 0 && (fs & ~KINDFLAGS) != 0 + } + + def isOneOf(flags: FlagSet, butNot: FlagSet): Boolean = isOneOf(flags) && !isOneOf(butNot) /** Does this flag set have all of the flags in given flag conjunction? * Pre: The intersection of the typeflags of both sets must be non-empty. @@ -507,7 +515,7 @@ object Flags { assert(AfterLoadFlags.isTermFlags && AfterLoadFlags.isTypeFlags) /** A value that's unstable unless complemented with a Stable flag */ - final val UnstableValue: FlagSet = Mutable | Method + final val UnstableValueFlags: FlagSet = Mutable | Method /** Flags that express the variance of a type parameter. */ final val VarianceFlags: FlagSet = Covariant | Contravariant @@ -601,7 +609,7 @@ object Flags { final val StableOrErased: FlagSet = StableRealizable | Erased /** Labeled `private`, or `final` */ - final val EffectivelyFinal: FlagSet = Private | Final + final val EffectivelyFinalFlags: FlagSet = Private | Final /** A private method */ final val PrivateMethod: FlagConjunction = allOf(Private, Method) @@ -659,10 +667,10 @@ object Flags { final val LocalContravariant: FlagConjunction = allOf(Local, Contravariant) /** Has defined or inherited default parameters */ - final val HasDefaultParams: FlagSet = DefaultParameterized | InheritedDefaultParams + final val HasDefaultParamsFlags: FlagSet = DefaultParameterized | InheritedDefaultParams /** Is valid forever */ - final val ValidForever: FlagSet = Package | Permanent | Scala2ExistentialCommon + final val ValidForeverFlags: FlagSet = Package | Permanent | Scala2ExistentialCommon /** A type parameter of a class or trait */ final val ClassTypeParam: FlagConjunction = allOf(TypeParam, Private) diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala index 333e982ec8b5..9d88b8289648 100644 --- a/compiler/src/dotty/tools/dotc/core/NameOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala @@ -123,7 +123,7 @@ object NameOps { /** If flags is a ModuleClass but not a Package, add module class suffix */ def adjustIfModuleClass(flags: FlagSet): N = likeSpacedN { - if (flags is (ModuleClass, butNot = Package)) name.asTypeName.moduleClassName + if (flags.is(ModuleClass, butNot = Package)) name.asTypeName.moduleClassName else name.toTermName.exclude(AvoidClashName) } diff --git a/compiler/src/dotty/tools/dotc/core/Scopes.scala b/compiler/src/dotty/tools/dotc/core/Scopes.scala index 0d775ed70bc9..8980761ba966 100644 --- a/compiler/src/dotty/tools/dotc/core/Scopes.scala +++ b/compiler/src/dotty/tools/dotc/core/Scopes.scala @@ -409,7 +409,7 @@ object Scopes { var irefs = new mutable.ListBuffer[TermRef] var e = lastEntry while (e ne null) { - if (e.sym is ImplicitOrImpliedOrGiven) { + if (e.sym.isOneOf(ImplicitOrImpliedOrGiven)) { val d = e.sym.denot irefs += TermRef(NoPrefix, d.symbol.asTerm).withDenot(d) } diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 63a6eb722b89..fd69854d76e2 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -40,7 +40,7 @@ trait SymDenotations { this: Context => initPrivateWithin: Symbol = NoSymbol)(implicit ctx: Context): SymDenotation = { val result = if (symbol.isClass) - if (initFlags is Package) new PackageClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin) + if (initFlags.is(Package)) new PackageClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin) else new ClassDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin) else new SymDenotation(symbol, owner, name, initFlags, initInfo, initPrivateWithin) result.validFor = stablePeriod @@ -48,7 +48,7 @@ trait SymDenotations { this: Context => } def stillValid(denot: SymDenotation): Boolean = - if (denot.is(ValidForever) || denot.isRefinementClass || denot.isImport) true + if (denot.isOneOf(ValidForeverFlags) || denot.isRefinementClass || denot.isImport) true else { val initial = denot.initial val firstPhaseId = initial.validFor.firstPhaseId.max(ctx.typerPhase.id) @@ -81,7 +81,7 @@ trait SymDenotations { this: Context => denot match { case denot: SymDenotation => def explainSym(msg: String) = explain(s"$msg\ndefined = ${denot.definedPeriodsString}") - if (denot.is(ValidForever) || denot.isRefinementClass) true + if (denot.isOneOf(ValidForeverFlags) || denot.isRefinementClass) true else { implicit val ctx = this val initial = denot.initial @@ -188,13 +188,23 @@ object SymDenotations { /** Has this denotation one of the flags in `fs` set? */ final def is(fs: FlagSet)(implicit ctx: Context): Boolean = - (if (isCurrent(fs)) myFlags else flags) is fs + (if (isCurrent(fs)) myFlags else flags).is(fs) + + /** Has this denotation one of the flags in `fs` set? */ + final def isOneOf(fs: FlagSet)(implicit ctx: Context): Boolean = + (if (isCurrent(fs)) myFlags else flags).isOneOf(fs) /** Has this denotation one of the flags in `fs` set, whereas none of the flags * in `butNot` are set? */ final def is(fs: FlagSet, butNot: FlagSet)(implicit ctx: Context): Boolean = - (if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags) is (fs, butNot) + (if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags).is(fs, 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 = + (if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags).isOneOf(fs, butNot) /** Has this denotation all of the flags in `fs` set? */ final def isAll(fs: FlagConjunction)(implicit ctx: Context): Boolean = @@ -220,7 +230,7 @@ object SymDenotations { println(i"${" " * indent}completing ${if (isType) "type" else "val"} $name") indent += 1 - if (myFlags is Touched) throw CyclicReference(this) + if (myFlags.is(Touched)) throw CyclicReference(this) myFlags |= Touched // completions.println(s"completing ${this.debugString}") @@ -236,7 +246,7 @@ object SymDenotations { } } else { - if (myFlags is Touched) throw CyclicReference(this) + if (myFlags.is(Touched)) throw CyclicReference(this) myFlags |= Touched completer.complete(this)(ctx.withPhase(validFor.firstPhaseId)) } @@ -262,7 +272,7 @@ object SymDenotations { * "avoid clash" suffix */ def effectiveName(implicit ctx: Context): Name = - if (this is ModuleClass) name.stripModuleClassSuffix + if (this.is(ModuleClass)) name.stripModuleClassSuffix else name.exclude(AvoidClashName) /** The privateWithin boundary, NoSymbol if no boundary is given. @@ -338,7 +348,7 @@ object SymDenotations { final def isCompleted: Boolean = !myInfo.isInstanceOf[LazyType] /** The denotation is in train of being completed */ - final def isCompleting: Boolean = (myFlags is Touched) && !isCompleted + final def isCompleting: Boolean = myFlags.is(Touched) && !isCompleted /** The completer of this denotation. @pre: Denotation is not yet completed */ final def completer: LazyType = myInfo.asInstanceOf[LazyType] @@ -502,13 +512,13 @@ object SymDenotations { /** Is symbol known to not exist, or potentially not completed yet? */ final def unforcedIsAbsent(implicit ctx: Context): Boolean = myInfo == NoType || - (this is (ModuleVal, butNot = Package)) && moduleClass.unforcedIsAbsent + (this.is(ModuleVal, butNot = Package)) && moduleClass.unforcedIsAbsent /** Is symbol known to not exist? */ final def isAbsent(implicit ctx: Context): Boolean = { ensureCompleted() (myInfo `eq` NoType) || - (this is (ModuleVal, butNot = Package)) && moduleClass.isAbsent + (this.is(ModuleVal, butNot = Package)) && moduleClass.isAbsent } /** Is this symbol the root class or its companion object? */ @@ -560,19 +570,19 @@ object SymDenotations { /** Is this symbol a package object or its module class? */ def isPackageObject(implicit ctx: Context): Boolean = - name.isPackageObjectName && (owner is Package) && (this is Module) + name.isPackageObjectName && owner.is(Package) && this.is(Module) /** Is this symbol an abstract type? */ - final def isAbstractType(implicit ctx: Context): Boolean = this is DeferredType + final def isAbstractType(implicit ctx: Context): Boolean = this.is(DeferredType) /** Is this symbol an alias type? */ - final def isAliasType(implicit ctx: Context): Boolean = isAbstractOrAliasType && !(this is Deferred) + final def isAliasType(implicit ctx: Context): Boolean = isAbstractOrAliasType && !this.is(Deferred) /** Is this symbol an abstract or alias type? */ final def isAbstractOrAliasType: Boolean = isType & !isClass /** Is this symbol an abstract type or type parameter? */ - final def isAbstractOrParamType(implicit ctx: Context): Boolean = this is DeferredOrTypeParam + final def isAbstractOrParamType(implicit ctx: Context): Boolean = this.isOneOf(DeferredOrTypeParam) /** Is this symbol a user-defined opaque alias type? */ def isOpaqueAlias(implicit ctx: Context): Boolean = is(Opaque) && !isClass @@ -608,7 +618,7 @@ object SymDenotations { def recur(sym: Symbol): Boolean = if (sym eq boundary) true else if (sym eq NoSymbol) false - else if ((sym is PackageClass) && !(boundary is PackageClass)) false + else if (sym.is(PackageClass) && !boundary.is(PackageClass)) false else recur(sym.owner) recur(symbol) } @@ -628,7 +638,7 @@ object SymDenotations { /** Is this denotation defined in the same scope and compilation unit as that symbol? */ final def isCoDefinedWith(other: Symbol)(implicit ctx: Context): Boolean = (this.effectiveOwner == other.effectiveOwner) && - ( !(this.effectiveOwner is PackageClass) + ( !this.effectiveOwner.is(PackageClass) || this.unforcedIsAbsent || other.unforcedIsAbsent || { // check if they are defined in the same file(or a jar) val thisFile = this.symbol.associatedFile @@ -652,7 +662,7 @@ object SymDenotations { * So the first call to a stable member might fail and/or produce side effects. */ final def isStableMember(implicit ctx: Context): Boolean = { - def isUnstableValue = is(UnstableValue) || info.isInstanceOf[ExprType] + def isUnstableValue = isOneOf(UnstableValueFlags) || info.isInstanceOf[ExprType] isType || is(StableRealizable) || !isUnstableValue } @@ -672,11 +682,11 @@ object SymDenotations { /** Is this a getter? */ final def isGetter(implicit ctx: Context): Boolean = - (this is Accessor) && !originalName.isSetterName && !originalName.isScala2LocalSuffix + this.is(Accessor) && !originalName.isSetterName && !originalName.isScala2LocalSuffix /** Is this a setter? */ final def isSetter(implicit ctx: Context): Boolean = - (this is Accessor) && + this.is(Accessor) && originalName.isSetterName && (!isCompleted || info.firstParamTypes.nonEmpty) // to avoid being fooled by var x_= : Unit = ... @@ -749,7 +759,7 @@ object SymDenotations { */ def isCorrectThisType(pre: Type): Boolean = pre match { case pre: ThisType => - (pre.cls eq owner) || (this is Protected) && pre.cls.derivesFrom(owner) + (pre.cls eq owner) || this.is(Protected) && pre.cls.derivesFrom(owner) case pre: TermRef => pre.symbol.moduleClass == owner case _ => @@ -772,7 +782,7 @@ object SymDenotations { !( isType // allow accesses to types from arbitrary subclasses fixes #4737 || pre.derivesFrom(cls) || isConstructor - || (owner is ModuleClass) // don't perform this check for static members + || owner.is(ModuleClass) // don't perform this check for static members )) fail( i""" @@ -789,10 +799,10 @@ object SymDenotations { ( boundary.isTerm || boundary.isRoot || (accessWithin(boundary) || accessWithinLinked(boundary)) && - ( !(this is Local) + ( !this.is(Local) || isCorrectThisType(pre) ) - || (this is Protected) && + || this.is(Protected) && ( superAccess || pre.isInstanceOf[ThisType] || ctx.phase.erasedTypes @@ -815,12 +825,12 @@ object SymDenotations { /** Is this symbol concrete, or that symbol deferred? */ def isAsConcrete(that: Symbol)(implicit ctx: Context): Boolean = - !(this is Deferred) || (that is Deferred) + !this.is(Deferred) || that.is(Deferred) /** Does this symbol have defined or inherited default parameters? */ def hasDefaultParams(implicit ctx: Context): Boolean = - if (this is HasDefaultParams) true - else if (this is NoDefaultParams) false + if (this.isOneOf(HasDefaultParamsFlags)) true + else if (this.is(NoDefaultParams)) false else { val result = allOverriddenSymbols exists (_.hasDefaultParams) setFlag(if (result) InheritedDefaultParams else NoDefaultParams) @@ -833,7 +843,7 @@ object SymDenotations { */ def isWeakOwner(implicit ctx: Context): Boolean = isPackageObject || - isTerm && !is(MethodOrLazy) && !isLocalDummy + isTerm && !isOneOf(MethodOrLazy) && !isLocalDummy def isSkolem: Boolean = name == nme.SKOLEM @@ -892,7 +902,7 @@ object SymDenotations { if (Config.showCompletions) println(s"missing module class for $name: $myInfo") NoSymbol } - if (this is ModuleVal) + if (this.is(ModuleVal)) myInfo match { case info: TypeRef => info.symbol case ExprType(info: TypeRef) => info.symbol // needed after uncurry, when module terms might be accessor defs @@ -904,7 +914,7 @@ object SymDenotations { } case _ => notFound } - else if (this is ModuleClass) + else if (this.is(ModuleClass)) symbol else NoSymbol @@ -914,7 +924,7 @@ object SymDenotations { * otherwise NoSymbol */ final def sourceModule(implicit ctx: Context): Symbol = - if (this is ModuleClass) + if (this.is(ModuleClass)) myInfo match { case ClassInfo(_, _, _, _, selfType) => def sourceOfSelf(tp: TypeOrSymbol): Symbol = tp match { @@ -928,7 +938,7 @@ object SymDenotations { case _ => NoSymbol } - else if (this is ModuleVal) + else if (this.is(ModuleVal)) symbol else NoSymbol @@ -997,7 +1007,7 @@ object SymDenotations { /** A symbol is effectively final if it cannot be overridden in a subclass */ final def isEffectivelyFinal(implicit ctx: Context): Boolean = - is(EffectivelyFinal) || !owner.isClass || owner.is(ModuleOrFinal) || owner.isAnonymousClass + isOneOf(EffectivelyFinalFlags) || !owner.isClass || owner.isOneOf(ModuleOrFinal) || owner.isAnonymousClass /** The class containing this denotation which has the given effective name. */ final def enclosingClassNamed(name: Name)(implicit ctx: Context): Symbol = { @@ -1028,11 +1038,11 @@ object SymDenotations { } final def isTopLevelClass(implicit ctx: Context): Boolean = - !this.exists || this.isEffectiveRoot || (this is PackageClass) || (this.owner is PackageClass) + !this.exists || this.isEffectiveRoot || this.is(PackageClass) || this.owner.is(PackageClass) /** The package class containing this denotation */ final def enclosingPackageClass(implicit ctx: Context): Symbol = - if (this is PackageClass) symbol else owner.enclosingPackageClass + if (this.is(PackageClass)) symbol else owner.enclosingPackageClass /** Register target as a companion; overridden in ClassDenotation */ def registerCompanion(target: Symbol)(implicit ctx: Context) = () @@ -1062,7 +1072,7 @@ object SymDenotations { companionType.suchThat(_.isClass).symbol final def scalacLinkedClass(implicit ctx: Context): Symbol = - if (this is ModuleClass) companionNamed(effectiveName.toTypeName) + if (this.is(ModuleClass)) companionNamed(effectiveName.toTypeName) else if (this.isClass) companionNamed(effectiveName.moduleClassName).sourceModule.moduleClass else NoSymbol @@ -1100,7 +1110,7 @@ object SymDenotations { * NoSymbol otherwise. */ final def linkedClass(implicit ctx: Context): Symbol = - if (this is ModuleClass) companionClass + if (this.is(ModuleClass)) companionClass else if (this.isClass) companionModule.moduleClass else NoSymbol @@ -1206,7 +1216,7 @@ object SymDenotations { @tailrec def loop(bcs: List[ClassSymbol]): Symbol = bcs match { case bc :: bcs1 => val sym = matchingDecl(bcs.head, base.thisType) - .suchThat(alt => !(alt is Deferred)).symbol + .suchThat(alt => !alt.is(Deferred)).symbol if (sym.exists) sym else loop(bcs.tail) case _ => NoSymbol @@ -1220,8 +1230,8 @@ object SymDenotations { * nonexistent or incomplete. */ @tailrec final def isIncompleteIn(base: Symbol)(implicit ctx: Context): Boolean = - (this is Deferred) || - (this is AbsOverride) && { + this.is(Deferred) || + this.is(AbsOverride) && { val supersym = superSymbolIn(base) supersym == NoSymbol || supersym.isIncompleteIn(base) } @@ -1234,10 +1244,10 @@ object SymDenotations { */ final def accessBoundary(base: Symbol)(implicit ctx: Context): Symbol = { val fs = flags - if (fs is Private) owner + if (fs.is(Private)) owner else if (fs.isAll(StaticProtected)) defn.RootClass else if (privateWithin.exists && !ctx.phase.erasedTypes) privateWithin - else if (fs is Protected) base + else if (fs.is(Protected)) base else defn.RootClass } @@ -1288,8 +1298,8 @@ object SymDenotations { * +1 = Covariant, -1 = Contravariant, 0 = Nonvariant, or not a type parameter */ final def variance(implicit ctx: Context): Int = - if (this is Covariant) 1 - else if (this is Contravariant) -1 + if (this.is(Covariant)) 1 + else if (this.is(Contravariant)) -1 else 0 /** The flags to be used for a type parameter owned by this symbol. @@ -1299,11 +1309,11 @@ object SymDenotations { override def toString: String = { val kindString = - if (myFlags is ModuleClass) "module class" + if (myFlags.is(ModuleClass)) "module class" else if (isClass) "class" else if (isType) "type" - else if (myFlags is Module) "module" - else if (myFlags is Method) "method" + else if (myFlags.is(Module)) "module" + else if (myFlags.is(Method)) "method" else "val" s"$kindString $name" } @@ -1470,7 +1480,7 @@ object SymDenotations { // ----- denotation fields and accessors ------------------------------ - if (initFlags is (Module, butNot = Package)) + if (initFlags.is(Module, butNot = Package)) assert(name.is(ModuleClassName), s"module naming inconsistency: ${name.debugString}") /** The symbol asserted to have type ClassSymbol */ @@ -1486,7 +1496,7 @@ object SymDenotations { */ private def typeParamsFromDecls(implicit ctx: Context) = unforcedDecls.filter(sym => - (sym is TypeParam) && sym.owner == symbol).asInstanceOf[List[TypeSymbol]] + (sym.is(TypeParam)) && sym.owner == symbol).asInstanceOf[List[TypeSymbol]] /** The type parameters of this class */ override final def typeParams(implicit ctx: Context): List[TypeSymbol] = { @@ -1521,7 +1531,7 @@ object SymDenotations { def superClass(implicit ctx: Context): Symbol = classParents match { case parent :: _ => val cls = parent.classSymbol - if (cls is Trait) NoSymbol else cls + if (cls.is(Trait)) NoSymbol else cls case _ => NoSymbol } @@ -1550,7 +1560,7 @@ object SymDenotations { private def computeThisType(implicit ctx: Context): Type = { val cls = symbol.asType - val pre = if (this is Package) NoPrefix else owner.thisType + val pre = if (this.is(Package)) NoPrefix else owner.thisType ThisType.raw(TypeRef(pre, cls)) } @@ -1749,7 +1759,7 @@ object SymDenotations { } override final def findMember(name: Name, pre: Type, required: FlagConjunction, excluded: FlagSet)(implicit ctx: Context): Denotation = { - val raw = if (excluded is Private) nonPrivateMembersNamed(name) else membersNamed(name) + val raw = if (excluded.is(Private)) nonPrivateMembersNamed(name) else membersNamed(name) raw.filterWithFlags(required, excluded).asSeenFrom(pre).toDenot(pre) } @@ -1903,7 +1913,7 @@ object SymDenotations { } def memberNames(keepOnly: NameFilter)(implicit onBehalf: MemberNames, ctx: Context): Set[Name] = - if ((this is PackageClass) || !Config.cacheMemberNames) + if (this.is(PackageClass) || !Config.cacheMemberNames) computeMemberNames(keepOnly) // don't cache package member names; they might change else { if (!memberNamesCache.isValid) memberNamesCache = MemberNames.newCache() @@ -1919,9 +1929,9 @@ object SymDenotations { maybeAdd(name) val ownSyms = if (keepOnly eq implicitFilter) - if (this is Package) Iterator.empty + if (this.is(Package)) Iterator.empty // implicits in package objects are added by the overriding `memberNames` in `PackageClassDenotation` - else info.decls.iterator filter (_ is ImplicitOrImpliedOrGiven) + else info.decls.iterator.filter(_.isOneOf(ImplicitOrImpliedOrGiven)) else info.decls.iterator for (sym <- ownSyms) maybeAdd(sym.name) names @@ -2151,7 +2161,7 @@ object SymDenotations { /** The type parameters computed by the completer before completion has finished */ def completerTypeParams(sym: Symbol)(implicit ctx: Context): List[TypeParamInfo] = - if (sym is Touched) Nil // return `Nil` instead of throwing a cyclic reference + if (sym.is(Touched)) Nil // return `Nil` instead of throwing a cyclic reference else sym.info.typeParams def decls: Scope = myDecls diff --git a/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala b/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala index c33248e6a59d..55f7409f91ec 100644 --- a/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -360,7 +360,7 @@ abstract class SymbolLoader extends LazyType { // as a stand in for loading. // An example for this situation is scala.reflect.Manifest, which exists // as a class in scala.reflect and as a val in scala.reflect.package. - if (rootDenot is ModuleClass) + if (rootDenot.is(ModuleClass)) ctx.newClassSymbol( rootDenot.owner, rootDenot.name.stripModuleClassSuffix.asTypeName, Synthetic, _ => NoType).classDenot @@ -370,7 +370,7 @@ abstract class SymbolLoader extends LazyType { (module, _) => new NoCompleter() withDecls newScope withSourceModule (_ => module)) .moduleClass.denot.asClass } - if (rootDenot is ModuleClass) (linkedDenot, rootDenot) + if (rootDenot.is(ModuleClass)) (linkedDenot, rootDenot) else (rootDenot, linkedDenot) } } diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index fe7bf0a7a95c..4c0a56802944 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -221,7 +221,7 @@ trait Symbols { this: Context => */ def newStubSymbol(owner: Symbol, name: Name, file: AbstractFile = null): Symbol = { def stubCompleter = new StubInfo() - val normalizedOwner = if (owner is ModuleVal) owner.moduleClass else owner + val normalizedOwner = if (owner.is(ModuleVal)) owner.moduleClass else owner typr.println(s"creating stub for ${name.show}, owner = ${normalizedOwner.denot.debugString}, file = $file") typr.println(s"decls = ${normalizedOwner.unforcedDecls.toList.map(_.debugString).mkString("\n ")}") // !!! DEBUG //if (base.settings.debug.value) throw new Error() @@ -359,7 +359,7 @@ trait Symbols { this: Context => def requiredPackage(path: PreName): TermSymbol = { val name = path.toTermName - base.staticRef(name, isPackage = true).requiredSymbol("package", name)(_ is Package).asTerm + base.staticRef(name, isPackage = true).requiredSymbol("package", name)(_.is(Package)).asTerm } def requiredPackageRef(path: PreName): TermRef = requiredPackage(path).termRef @@ -394,14 +394,14 @@ trait Symbols { this: Context => def requiredModule(path: PreName): TermSymbol = { val name = path.toTermName - base.staticRef(name).requiredSymbol("object", name)(_ is Module).asTerm + base.staticRef(name).requiredSymbol("object", name)(_.is(Module)).asTerm } def requiredModuleRef(path: PreName): TermRef = requiredModule(path).termRef def requiredMethod(path: PreName): TermSymbol = { val name = path.toTermName - base.staticRef(name).requiredSymbol("method", name)(_ is Method).asTerm + base.staticRef(name).requiredSymbol("method", name)(_.is(Method)).asTerm } def requiredMethodRef(path: PreName): TermRef = requiredMethod(path).termRef @@ -454,7 +454,7 @@ object Symbols { def retainsDefTree(implicit ctx: Context): Boolean = ctx.settings.YretainTrees.value || denot.owner.isTerm || // no risk of leaking memory after a run for these - denot.is(InlineOrProxy) // need to keep inline info + denot.isOneOf(InlineOrProxy) // need to keep inline info /** The last denotation of this symbol */ private[this] var lastDenot: SymDenotation = _ @@ -555,7 +555,7 @@ object Symbols { final def entered(implicit ctx: Context): this.type = { assert(this.owner.isClass, s"symbol ($this) entered the scope of non-class owner ${this.owner}") // !!! DEBUG this.owner.asClass.enter(this) - if (this is Module) this.owner.asClass.enter(this.moduleClass) + if (this.is(Module)) this.owner.asClass.enter(this.moduleClass) this } @@ -569,7 +569,7 @@ object Symbols { else { if (this.owner.is(Package)) { denot.validFor |= InitialPeriod - if (this is Module) this.moduleClass.validFor |= InitialPeriod + if (this.is(Module)) this.moduleClass.validFor |= InitialPeriod } else this.owner.asClass.ensureFreshScopeAfter(phase) assert(isPrivate || phase.changesMembers, i"$this entered in ${this.owner} at undeclared phase $phase") @@ -579,7 +579,7 @@ object Symbols { /** Remove symbol from scope of owning class */ final def drop()(implicit ctx: Context): Unit = { this.owner.asClass.delete(this) - if (this is Module) this.owner.asClass.delete(this.moduleClass) + if (this.is(Module)) this.owner.asClass.delete(this.moduleClass) } /** Remove symbol from scope of owning class after given `phase`. Create a fresh @@ -760,7 +760,7 @@ object Symbols { /** The source or class file from which this class was generated, null if not applicable. */ override def associatedFile(implicit ctx: Context): AbstractFile = - if (assocFile != null || (this.owner is PackageClass) || this.isEffectiveRoot) assocFile + if (assocFile != null || (this.owner.is(PackageClass)) || this.isEffectiveRoot) assocFile else super.associatedFile private[this] var mySource: SourceFile = NoSource diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index ee785428d4b8..a61bc0cf2a9a 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -2151,7 +2151,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w // println(s"disjoint(${tp1.show}, ${tp2.show})") /** Can we enumerate all instantiations of this type? */ def isClosedSum(tp: Symbol): Boolean = - tp.is(Sealed) && tp.is(AbstractOrTrait) && !tp.hasAnonymousChild + tp.is(Sealed) && tp.isOneOf(AbstractOrTrait) && !tp.hasAnonymousChild /** Splits a closed type into a disjunction of smaller types. * It should hold that `tp` and `decompose(tp).reduce(_ or _)` diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index 79a5dfb9cce9..4e9d24db470b 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -232,7 +232,7 @@ object TypeErasure { } /** Is `tp` an abstract type or polymorphic type parameter that has `Any`, `AnyVal`, - * or a universal trait as upper bound and that is not Java defined? Arrays of such types are + * or a universal trait as upper bound and that.is(not) Java defined? Arrays of such types are * erased to `Object` instead of `Object[]`. */ def isUnboundedGeneric(tp: Type)(implicit ctx: Context): Boolean = tp.dealias match { @@ -473,7 +473,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean case tp: PolyType => this(tp.resultType) case tp @ ClassInfo(pre, cls, parents, decls, _) => - if (cls is Package) tp + if (cls.is(Package)) tp else { def eraseParent(tp: Type) = tp.dealias match { // note: can't be opaque, since it's a class parent case tp: AppliedType if tp.tycon.isRef(defn.PairClass) => defn.ObjectType @@ -484,7 +484,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean else parents.mapConserve(eraseParent) match { case tr :: trs1 => assert(!tr.classSymbol.is(Trait), i"$cls has bad parents $parents%, %") - val tr1 = if (cls is Trait) defn.ObjectType else tr + val tr1 = if (cls.is(Trait)) defn.ObjectType else tr tr1 :: trs1.filterNot(_ isRef defn.ObjectClass) case nil => nil } @@ -520,7 +520,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean */ def eraseInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type = tp match { case ExprType(rt) => - if (sym is Param) apply(tp) + if (sym.is(Param)) apply(tp) // Note that params with ExprTypes are eliminated by ElimByName, // but potentially re-introduced by ResolveSuper, when we add // forwarders to mixin methods. @@ -547,7 +547,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean private def eraseNormalClassRef(tref: TypeRef)(implicit ctx: Context): Type = { val cls = tref.symbol.asClass - (if (cls.owner is Package) normalizeClass(cls) else cls).typeRef + (if (cls.owner.is(Package)) normalizeClass(cls) else cls).typeRef } /** The erasure of a function result type. */ diff --git a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala index 1deb39636ba4..2f179b7e4e20 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErrors.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErrors.scala @@ -142,7 +142,7 @@ class CyclicReference private (val denot: SymDenotation) extends TypeError { } } // Give up and give generic errors. - else if (cycleSym.is(ImplicitOrImpliedOrGiven, butNot = Method) && cycleSym.owner.isTerm) + else if (cycleSym.isOneOf(ImplicitOrImpliedOrGiven, butNot = Method) && cycleSym.owner.isTerm) CyclicReferenceInvolvingImplicit(cycleSym) else CyclicReferenceInvolving(denot) diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 4e1623bc2c20..90b4234b44dc 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -338,8 +338,8 @@ trait TypeOps { this: Context => // TODO: Make standalone object. tpe else tpe.prefix match { - case pre: ThisType if pre.cls is Package => tryInsert(pre.cls) - case pre: TermRef if pre.symbol is Package => tryInsert(pre.symbol.moduleClass) + case pre: ThisType if pre.cls.is(Package) => tryInsert(pre.cls) + case pre: TermRef if pre.symbol.is(Package) => tryInsert(pre.symbol.moduleClass) case _ => tpe } } diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 0a58a968e8a3..199481e48cb9 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -557,7 +557,7 @@ object Types { case tp: TermRef => go (tp.underlying match { case mt: MethodType - if mt.paramInfos.isEmpty && (tp.symbol is StableRealizable) => mt.resultType + if mt.paramInfos.isEmpty && tp.symbol.is(StableRealizable) => mt.resultType case tp1 => tp1 }) case tp: TypeRef => @@ -764,7 +764,7 @@ object Types { /** The set of abstract term members of this type. */ final def abstractTermMembers(implicit ctx: Context): Seq[SingleDenotation] = track("abstractTermMembers") { memberDenots(abstractTermNameFilter, - (name, buf) => buf ++= nonPrivateMember(name).altsWith(_ is Deferred)) + (name, buf) => buf ++= nonPrivateMember(name).altsWith(_.is(Deferred))) } /** The set of abstract type members of this type. */ @@ -797,7 +797,7 @@ object Types { */ final def implicitMembers(kind: FlagSet)(implicit ctx: Context): List[TermRef] = track("implicitMembers") { memberDenots(implicitFilter, - (name, buf) => buf ++= member(name).altsWith(_.is(ImplicitOrImpliedOrGivenTerm & kind))) + (name, buf) => buf ++= member(name).altsWith(_.isOneOf(ImplicitOrImpliedOrGivenTerm & kind))) .toList.map(d => TermRef(this, d.symbol.asTerm)) } @@ -2125,7 +2125,7 @@ object Types { } if (base.isAnd == variance >= 0) tp1 & tp2 else tp1 | tp2 case _ => - if (pre.termSymbol is Package) argForParam(pre.select(nme.PACKAGE)) + if (pre.termSymbol.is(Package)) argForParam(pre.select(nme.PACKAGE)) else if (pre.isBottomType) pre else NoType } @@ -3972,7 +3972,7 @@ object Types { selfTypeCache = { val givenSelf = cls.givenSelfType if (!givenSelf.isValueType) appliedRef - else if (cls is Module) givenSelf + else if (cls.is(Module)) givenSelf else if (ctx.erasedTypes) appliedRef else AndType(givenSelf, appliedRef) } @@ -4325,7 +4325,7 @@ object Types { case et: ExprType => true case _ => false } - if ((tp.cls is Trait) || zeroParams(tp.cls.primaryConstructor.info)) tp // !!! needs to be adapted once traits have parameters + if ((tp.cls.is(Trait)) || zeroParams(tp.cls.primaryConstructor.info)) tp // !!! needs to be adapted once traits have parameters else NoType case tp: AppliedType => zeroParamClass(tp.superType) @@ -5121,7 +5121,7 @@ object Types { def apply(pre: Type, name: Name)(implicit ctx: Context): Boolean = name.isTypeName && { val mbr = pre.nonPrivateMember(name) - (mbr.symbol is Deferred) && mbr.info.isInstanceOf[RealTypeBounds] + (mbr.symbol.is(Deferred)) && mbr.info.isInstanceOf[RealTypeBounds] } } @@ -5137,7 +5137,7 @@ object Types { /** A filter for names of deferred term definitions of a given type */ object abstractTermNameFilter extends NameFilter { def apply(pre: Type, name: Name)(implicit ctx: Context): Boolean = - name.isTermName && pre.nonPrivateMember(name).hasAltWith(_.symbol is Deferred) + name.isTermName && pre.nonPrivateMember(name).hasAltWith(_.symbol.is(Deferred)) } /** A filter for names of type aliases of a given type */ diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 661494ec19be..2fb6d7f20e69 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -75,7 +75,7 @@ class ClassfileParser( classRoot.info = (new NoCompleter).withDecls(instanceScope) moduleRoot.info = (new NoCompleter).withDecls(staticScope).withSourceModule(_ => staticModule) - private def currentIsTopLevel(implicit ctx: Context) = classRoot.owner is Flags.PackageClass + private def currentIsTopLevel(implicit ctx: Context) = classRoot.owner.is(Flags.PackageClass) private def mismatchError(className: SimpleName) = throw new IOException(s"class file '${in.file.canonicalPath}' has location not matching its contents: contains class $className") @@ -195,7 +195,7 @@ class ClassfileParser( /** Add type parameters of enclosing classes */ def addEnclosingTParams()(implicit ctx: Context): Unit = { var sym = classRoot.owner - while (sym.isClass && !(sym is Flags.ModuleClass)) { + while (sym.isClass && !sym.is(Flags.ModuleClass)) { for (tparam <- sym.typeParams) { classTParams = classTParams.updated(tparam.name, tparam) } @@ -210,7 +210,7 @@ class ClassfileParser( if (method) Flags.Method | methodTranslation.flags(jflags) else fieldTranslation.flags(jflags) val name = pool.getName(in.nextChar) - if (!(sflags is Flags.Private) || name == nme.CONSTRUCTOR) { + if (!sflags.is(Flags.Private) || name == nme.CONSTRUCTOR) { val member = ctx.newSymbol( getOwner(jflags), name, sflags, memberCompleter, coord = start) getScope(jflags).enter(member) @@ -267,7 +267,7 @@ class ClassfileParser( denot.info = translateTempPoly(parseAttributes(sym, denot.info)) if (isConstructor) normalizeConstructorInfo() - if ((denot is Flags.Method) && (jflags & JAVA_ACC_VARARGS) != 0) + if (denot.is(Flags.Method) && (jflags & JAVA_ACC_VARARGS) != 0) denot.info = arrayToRepeated(denot.info) // seal java enums @@ -276,7 +276,7 @@ class ClassfileParser( if (!enumClass.exists) ctx.warning(s"no linked class for java enum $sym in ${sym.owner}. A referencing class file might be missing an InnerClasses entry.") else { - if (!(enumClass is Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed.toFlags) + if (!enumClass.is(Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed.toFlags) enumClass.addAnnotation(Annotation.Child(sym)) } } @@ -318,7 +318,7 @@ class ClassfileParser( case BOOL_TAG => defn.BooleanType case 'L' => def processInner(tp: Type): Type = tp match { - case tp: TypeRef if !(tp.symbol.owner is Flags.ModuleClass) => + case tp: TypeRef if !tp.symbol.owner.is(Flags.ModuleClass) => TypeRef(processInner(tp.prefix.widen), tp.symbol.asType) case _ => tp @@ -663,7 +663,7 @@ class ClassfileParser( ).entered for ((attr, i) <- attrs.zipWithIndex) if (attr.hasAnnotation(defn.AnnotationDefaultAnnot)) { - constr.setFlag(Flags.HasDefaultParams) + constr.setFlag(Flags.DefaultParameterized) addDefaultGetter(attr, i) } } diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala index 6532fc60afdc..b4ec6e45e841 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala @@ -618,11 +618,11 @@ class TreePickler(pickler: TastyPickler) { var flags = sym.flags val privateWithin = sym.privateWithin if (privateWithin.exists) { - writeByte(if (flags is Protected) PROTECTEDqualified else PRIVATEqualified) + writeByte(if (flags.is(Protected)) PROTECTEDqualified else PRIVATEqualified) pickleType(privateWithin.typeRef) flags = flags &~ Protected } - if ((flags is ParamAccessor) && sym.isTerm && !sym.isSetter) + if (flags.is(ParamAccessor) && sym.isTerm && !sym.isSetter) flags = flags &~ ParamAccessor // we only generate a tag for parameter setters pickleFlags(flags, sym.isTerm) sym.annotations.foreach(pickleAnnotation(sym, _)) @@ -634,44 +634,44 @@ class TreePickler(pickler: TastyPickler) { assert(isModifierTag(tag)) writeByte(tag) } - if (flags is Private) writeModTag(PRIVATE) - if (flags is Protected) writeModTag(PROTECTED) + if (flags.is(Private)) writeModTag(PRIVATE) + if (flags.is(Protected)) writeModTag(PROTECTED) if (flags.is(Final, butNot = Module)) writeModTag(FINAL) - if (flags is Case) writeModTag(CASE) - if (flags is Override) writeModTag(OVERRIDE) - if (flags is Inline) writeModTag(INLINE) - if (flags is InlineProxy) writeModTag(INLINEPROXY) - if (flags is Macro) writeModTag(MACRO) - if (flags is JavaStatic) writeModTag(STATIC) - if (flags is Module) writeModTag(OBJECT) - if (flags is Enum) writeModTag(ENUM) - if (flags is Local) writeModTag(LOCAL) - if (flags is Synthetic) writeModTag(SYNTHETIC) - if (flags is Artifact) writeModTag(ARTIFACT) - if (flags is Scala2x) writeModTag(SCALA2X) + if (flags.is(Case)) writeModTag(CASE) + if (flags.is(Override)) writeModTag(OVERRIDE) + if (flags.is(Inline)) writeModTag(INLINE) + if (flags.is(InlineProxy)) writeModTag(INLINEPROXY) + if (flags.is(Macro)) writeModTag(MACRO) + if (flags.is(JavaStatic)) writeModTag(STATIC) + if (flags.is(Module)) writeModTag(OBJECT) + if (flags.is(Enum)) writeModTag(ENUM) + if (flags.is(Local)) writeModTag(LOCAL) + if (flags.is(Synthetic)) writeModTag(SYNTHETIC) + if (flags.is(Artifact)) writeModTag(ARTIFACT) + if (flags.is(Scala2x)) writeModTag(SCALA2X) if (isTerm) { - if (flags is Implicit) writeModTag(IMPLICIT) - if (flags is Implied) writeModTag(IMPLIED) - if (flags is Erased) writeModTag(ERASED) + if (flags.is(Implicit)) writeModTag(IMPLICIT) + if (flags.is(Implied)) writeModTag(IMPLIED) + if (flags.is(Erased)) writeModTag(ERASED) if (flags.is(Lazy, butNot = Module)) writeModTag(LAZY) - if (flags is AbsOverride) { writeModTag(ABSTRACT); writeModTag(OVERRIDE) } - if (flags is Mutable) writeModTag(MUTABLE) - if (flags is Accessor) writeModTag(FIELDaccessor) - if (flags is CaseAccessor) writeModTag(CASEaccessor) - if (flags is DefaultParameterized) writeModTag(DEFAULTparameterized) - if (flags is StableRealizable) writeModTag(STABLE) - if (flags is Extension) writeModTag(EXTENSION) - if (flags is Given) writeModTag(GIVEN) - if (flags is ParamAccessor) writeModTag(PARAMsetter) - if (flags is Exported) writeModTag(EXPORTED) - assert(!(flags is Label)) + if (flags.is(AbsOverride)) { writeModTag(ABSTRACT); writeModTag(OVERRIDE) } + if (flags.is(Mutable)) writeModTag(MUTABLE) + if (flags.is(Accessor)) writeModTag(FIELDaccessor) + if (flags.is(CaseAccessor)) writeModTag(CASEaccessor) + if (flags.is(DefaultParameterized)) writeModTag(DEFAULTparameterized) + if (flags.is(StableRealizable)) writeModTag(STABLE) + if (flags.is(Extension)) writeModTag(EXTENSION) + if (flags.is(Given)) writeModTag(GIVEN) + if (flags.is(ParamAccessor)) writeModTag(PARAMsetter) + if (flags.is(Exported)) writeModTag(EXPORTED) + assert(!(flags.is(Label))) } else { - if (flags is Sealed) writeModTag(SEALED) - if (flags is Abstract) writeModTag(ABSTRACT) - if (flags is Trait) writeModTag(TRAIT) - if (flags is Covariant) writeModTag(COVARIANT) - if (flags is Contravariant) writeModTag(CONTRAVARIANT) - if (flags is Opaque) writeModTag(OPAQUE) + if (flags.is(Sealed)) writeModTag(SEALED) + if (flags.is(Abstract)) writeModTag(ABSTRACT) + if (flags.is(Trait)) writeModTag(TRAIT) + if (flags.is(Covariant)) writeModTag(COVARIANT) + if (flags.is(Contravariant)) writeModTag(CONTRAVARIANT) + if (flags.is(Opaque)) writeModTag(OPAQUE) } } diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 72ef5aecc939..c81148b223c2 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -451,12 +451,12 @@ class TreeUnpickler(reader: TastyReader, private def normalizeFlags(tag: Int, givenFlags: FlagSet, name: Name, isAbsType: Boolean, rhsIsEmpty: Boolean)(implicit ctx: Context): FlagSet = { val lacksDefinition = rhsIsEmpty && - name.isTermName && !name.isConstructorName && !givenFlags.is(TermParamOrAccessor) || + name.isTermName && !name.isConstructorName && !givenFlags.isOneOf(TermParamOrAccessor) || isAbsType var flags = givenFlags if (lacksDefinition && tag != PARAM) flags |= Deferred if (tag == DEFDEF) flags |= Method - if (givenFlags is Module) + if (givenFlags.is(Module)) flags = flags | (if (tag == VALDEF) ModuleValCreationFlags else ModuleClassCreationFlags) if (ctx.owner.isClass) { if (tag == TYPEPARAM) flags |= Param @@ -538,7 +538,7 @@ class TreeUnpickler(reader: TastyReader, pickling.println(i"creating symbol $name at $start with flags $givenFlags") val flags = normalizeFlags(tag, givenFlags, name, isAbsType, rhsIsEmpty) def adjustIfModule(completer: LazyType) = - if (flags is Module) ctx.adjustModuleCompleter(completer, name) else completer + if (flags.is(Module)) ctx.adjustModuleCompleter(completer, name) else completer val coord = coordAt(start) val sym = roots.find(root => (root.owner eq ctx.owner) && root.name == name) match { @@ -677,7 +677,7 @@ class TreeUnpickler(reader: TastyReader, case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM => val sym = symbolAtCurrent() skipTree() - if (sym.isTerm && !sym.is(MethodOrLazyOrDeferred)) + if (sym.isTerm && !sym.isOneOf(MethodOrLazyOrDeferred)) initsFlags = EmptyFlags else if (sym.isClass || sym.is(Method, butNot = Deferred) && !sym.isConstructor) diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 7941e2a71b59..5f36bf25f1b3 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -102,7 +102,7 @@ object Scala2Unpickler { case cinfo => (Nil, cinfo) } val ost = - if ((selfInfo eq NoType) && (denot is ModuleClass) && denot.sourceModule.exists) + if ((selfInfo eq NoType) && denot.is(ModuleClass) && denot.sourceModule.exists) // it seems sometimes the source module does not exist for a module class. // An example is `scala.reflect.internal.Trees.Template$. Without the // `denot.sourceModule.exists` provision i859.scala crashes in the backend. @@ -129,7 +129,7 @@ object Scala2Unpickler { claz.registerCompanion(module) } - if (denot.flagsUNSAFE is Module) + if (denot.flagsUNSAFE.is(Module)) registerCompanionPair(denot.classSymbol, scalacCompanion) else registerCompanionPair(scalacCompanion, denot.classSymbol) @@ -384,7 +384,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas // return NoSymbol if (tag == EXTMODCLASSref) { - val module = owner.info.decl(name.toTermName).suchThat(_ is Module) + val module = owner.info.decl(name.toTermName).suchThat(_.is(Module)) module.info // force it, as completer does not yet point to module class. module.symbol.moduleClass @@ -438,31 +438,31 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas var flags = unpickleScalaFlags(readLongNat(), name.isTypeName) if (flags.isAll(DefaultParameter)) { // DefaultParameterized flag now on method, not parameter - //assert(flags is Param, s"$name0 in $owner") + //assert(flags.is(Param), s"$name0 in $owner") flags = flags &~ DefaultParameterized owner.setFlag(DefaultParameterized) } name = name.adjustIfModuleClass(flags) - if (flags is Method) { + if (flags.is(Method)) { name = if (name == nme.TRAIT_CONSTRUCTOR) nme.CONSTRUCTOR else name.asTermName.unmangle(Scala2MethodNameKinds) } - if ((flags is Scala2ExpandedName)) { + if ((flags.is(Scala2ExpandedName))) { name = name.unmangle(ExpandedName) flags = flags &~ Scala2ExpandedName } - if (flags is Scala2SuperAccessor) { + if (flags.is(Scala2SuperAccessor)) { name = name.asTermName.unmangle(SuperAccessorName) flags = flags &~ Scala2SuperAccessor } name = name.mapLast(_.decode) def nameMatches(rootName: Name) = name == rootName - def isClassRoot = nameMatches(classRoot.name) && (owner == classRoot.owner) && !(flags is ModuleClass) - def isModuleClassRoot = nameMatches(moduleClassRoot.name) && (owner == moduleClassRoot.owner) && (flags is Module) - def isModuleRoot = nameMatches(moduleClassRoot.name.sourceModuleName) && (owner == moduleClassRoot.owner) && (flags is Module) + def isClassRoot = nameMatches(classRoot.name) && (owner == classRoot.owner) && !flags.is(ModuleClass) + def isModuleClassRoot = nameMatches(moduleClassRoot.name) && (owner == moduleClassRoot.owner) && flags.is(Module) + def isModuleRoot = nameMatches(moduleClassRoot.name.sourceModuleName) && (owner == moduleClassRoot.owner) && flags.is(Module) //if (isClassRoot) println(s"classRoot of $classRoot found at $readIndex, flags = $flags") // !!! DEBUG //if (isModuleRoot) println(s"moduleRoot of $moduleRoot found at $readIndex, flags = $flags") // !!! DEBUG @@ -487,7 +487,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas if (sym.isClass) { sym.setFlag(Scala2x) } - if (!(isRefinementClass(sym) || isUnpickleRoot(sym) || (sym is Scala2Existential))) { + if (!(isRefinementClass(sym) || isUnpickleRoot(sym) || sym.is(Scala2Existential))) { val owner = sym.owner if (owner.isClass) owner.asClass.enter(sym, symScope(owner)) @@ -501,7 +501,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas case TYPEsym | ALIASsym => var name1 = name.asTypeName var flags1 = flags - if (flags is TypeParam) flags1 |= owner.typeParamCreationFlags + if (flags.is(TypeParam)) flags1 |= owner.typeParamCreationFlags ctx.newSymbol(owner, name1, flags1, localMemberUnpickler, coord = start) case CLASSsym => var infoRef = readNat() @@ -518,10 +518,10 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas else { def completer(cls: Symbol) = { val unpickler = new ClassUnpickler(infoRef) withDecls symScope(cls) - if (flags is ModuleClass) + if (flags.is(ModuleClass)) unpickler withSourceModule (implicit ctx => cls.owner.info.decls.lookup(cls.name.sourceModuleName) - .suchThat(_ is Module).symbol) + .suchThat(_.is(Module)).symbol) else unpickler } ctx.newClassSymbol(owner, name.asTypeName, flags, completer, coord = start) @@ -535,7 +535,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas } else ctx.newSymbol(owner, name.asTermName, flags, new LocalUnpickler() withModuleClass(implicit ctx => owner.info.decls.lookup(name.moduleClassName) - .suchThat(_ is Module).symbol) + .suchThat(_.is(Module)).symbol) , coord = start) case _ => errorBadSignature("bad symbol tag: " + tag) @@ -734,7 +734,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas pre = SuperType(thispre, base) } } - case NoPrefix if sym is TypeParam => + case NoPrefix if sym.is(TypeParam) => pre = sym.owner.thisType case _ => } diff --git a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala index 6f9561f4d393..24817953b93f 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala @@ -408,7 +408,7 @@ object Interactive { if (sym.isClass) { case td: TypeDef => val treeSym = td.symbol - (treeSym != sym || !treeSym.is(AbstractOrTrait)) && treeSym.derivesFrom(sym) + (treeSym != sym || !treeSym.isOneOf(AbstractOrTrait)) && treeSym.derivesFrom(sym) case _ => false } else { diff --git a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala index f273a932698b..66f8edf750b6 100644 --- a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala @@ -494,7 +494,7 @@ object JavaParsers { } } else { var mods1 = mods - if (mods is Flags.Abstract) mods1 = mods &~ Flags.Abstract + if (mods.is(Flags.Abstract)) mods1 = mods &~ Flags.Abstract nameOffset = in.offset val name = ident() if (in.token == LPAREN) { @@ -502,7 +502,7 @@ object JavaParsers { val vparams = formalParams() if (!isVoid) rtpt = optArrayBrackets(rtpt) optThrows() - val bodyOk = !inInterface || (mods is Flags.DefaultMethod) + val bodyOk = !inInterface || (mods.is(Flags.DefaultMethod)) val body = if (bodyOk && in.token == LBRACE) { methodBody() @@ -580,9 +580,9 @@ object JavaParsers { def varDecl(mods: Modifiers, tpt: Tree, name: TermName): ValDef = { val tpt1 = optArrayBrackets(tpt) - if (in.token == EQUALS && !(mods is Flags.Param)) skipTo(COMMA, SEMI) - val mods1 = if (mods is Flags.Final) mods else mods | Flags.Mutable - ValDef(name, tpt1, if (mods is Flags.Param) EmptyTree else unimplementedExpr).withMods(mods1) + if (in.token == EQUALS && !mods.is(Flags.Param)) skipTo(COMMA, SEMI) + val mods1 = if (mods.is(Flags.Final)) mods else mods | Flags.Mutable + ValDef(name, tpt1, if (mods.is(Flags.Param)) EmptyTree else unimplementedExpr).withMods(mods1) } def memberDecl(start: Offset, mods: Modifiers, parentToken: Int, parentTParams: List[TypeDef]): List[Tree] = in.token match { @@ -738,7 +738,7 @@ object JavaParsers { } else { if (in.token == ENUM || definesInterface(in.token)) mods |= Flags.JavaStatic val decls = memberDecl(start, mods, parentToken, parentTParams) - (if ((mods is Flags.JavaStatic) || inInterface && !(decls exists (_.isInstanceOf[DefDef]))) + (if ((mods.is(Flags.JavaStatic)) || inInterface && !(decls exists (_.isInstanceOf[DefDef]))) statics else members) ++= decls diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index ca30f41c2d6f..b54edbc54ec6 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -887,7 +887,7 @@ object Parsers { def functionRest(params: List[Tree]): Tree = atSpan(start, accept(ARROW)) { val t = typ() - if (imods.is(Given | Erased)) new FunctionWithMods(params, t, imods) + if (imods.isOneOf(Given | Erased)) new FunctionWithMods(params, t, imods) else Function(params, t) } def funArgTypesRest(first: Tree, following: () => Tree) = { @@ -968,7 +968,7 @@ object Parsers { case MATCH => matchType(t) case FORSOME => syntaxError(ExistentialTypesNoLongerSupported()); t case _ => - if (imods.is(ImplicitOrGiven) && !t.isInstanceOf[FunctionWithMods]) + if (imods.isOneOf(ImplicitOrGiven) && !t.isInstanceOf[FunctionWithMods]) syntaxError("Types with implicit keyword can only be function types `implicit (...) => ...`", implicitKwPos(start)) if (imods.is(Erased) && !t.isInstanceOf[FunctionWithMods]) syntaxError("Types with erased keyword can only be function types `erased (...) => ...`", implicitKwPos(start)) @@ -2037,7 +2037,7 @@ object Parsers { * Contract `abstract' and `override' to ABSOVERRIDE */ private def normalize(mods: Modifiers): Modifiers = - if ((mods is Private) && mods.hasPrivateWithin) + if (mods.is(Private) && mods.hasPrivateWithin) normalize(mods &~ Private) else if (mods.isAll(AbstractAndOverride)) normalize(addFlag(mods &~ (Abstract | Override), AbsOverride)) @@ -2049,7 +2049,7 @@ object Parsers { val name = in.name val mod = atSpan(in.skipToken()) { modOfToken(tok, name) } - if (mods is mod.flags) syntaxError(RepeatedModifier(mod.flags.flagsString)) + if (mods.isOneOf(mod.flags)) syntaxError(RepeatedModifier(mod.flags.flagsString)) addMod(mods, mod) } @@ -2080,7 +2080,7 @@ object Parsers { */ def accessQualifierOpt(mods: Modifiers): Modifiers = if (in.token == LBRACKET) { - if ((mods is Local) || mods.hasPrivateWithin) + if (mods.is(Local) || mods.hasPrivateWithin) syntaxError(DuplicatePrivateProtectedQualifier()) inBrackets { if (in.token == THIS) { in.nextToken(); mods | Local } @@ -2254,8 +2254,8 @@ object Parsers { atSpan(start, nameStart) { val name = ident() accept(COLON) - if (in.token == ARROW && ofClass && !(mods is Local)) - syntaxError(VarValParametersMayNotBeCallByName(name, mods is Mutable)) + if (in.token == ARROW && ofClass && !mods.is(Local)) + syntaxError(VarValParametersMayNotBeCallByName(name, mods.is(Mutable))) val tpt = paramType() val default = if (in.token == EQUALS) { in.nextToken(); expr() } @@ -2283,7 +2283,7 @@ object Parsers { inParens { if (in.token == RPAREN && !prefix && !impliedMods.is(Given)) Nil else { - if (in.token == IMPLICIT && !impliedMods.is(Given | Erased)) + if (in.token == IMPLICIT && !impliedMods.isOneOf(Given | Erased)) impliedMods = addMod(impliedMods, atSpan(accept(IMPLICIT)) { Mod.Implicit() }) val clause = if (prefix) param() :: Nil @@ -2518,7 +2518,7 @@ object Parsers { val rhs = if (tpt.isEmpty || in.token == EQUALS) { accept(EQUALS) - if (in.token == USCORE && !tpt.isEmpty && (mods is Mutable) && + if (in.token == USCORE && !tpt.isEmpty && mods.is(Mutable) && (lhs.toList forall (_.isInstanceOf[Ident]))) { wildcardIdent() } else { @@ -2553,7 +2553,7 @@ object Parsers { if (in.token == THIS) { in.nextToken() val vparamss = paramClauses() - if (vparamss.isEmpty || vparamss.head.take(1).exists(_.mods.is(ImplicitOrGiven))) + if (vparamss.isEmpty || vparamss.head.take(1).exists(_.mods.isOneOf(ImplicitOrGiven))) in.token match { case LBRACKET => syntaxError("no type parameters allowed here") case EOF => incompleteInputError(AuxConstructorNeedsNonImplicitParameter()) diff --git a/compiler/src/dotty/tools/dotc/printing/DecompilerPrinter.scala b/compiler/src/dotty/tools/dotc/printing/DecompilerPrinter.scala index 3f540530c2ca..7ce03efbadff 100644 --- a/compiler/src/dotty/tools/dotc/printing/DecompilerPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/DecompilerPrinter.scala @@ -48,7 +48,7 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) { override protected def templateText(tree: TypeDef, impl: Template): Text = { val decl = - if (!tree.mods.is(Module)) modText(tree.mods, tree.symbol, keywordStr(if ((tree).mods is Trait) "trait" else "class"), isType = true) + if (!tree.mods.is(Module)) modText(tree.mods, tree.symbol, keywordStr(if (tree.mods.is(Trait)) "trait" else "class"), isType = true) else modText(tree.mods, tree.symbol, keywordStr("object"), isType = false) decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) } ~ "" } diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index 4beb0c36754f..7c932a976d4e 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -84,7 +84,7 @@ class PlainPrinter(_ctx: Context) extends Printer { * to the name of the owner. */ protected def hasMeaninglessName(sym: Symbol): Boolean = ( - (sym is Param) && sym.owner.isSetter // x$1 + (sym.is(Param)) && sym.owner.isSetter // x$1 || sym.isClassConstructor // this || (sym.name == nme.PACKAGE) // package ) @@ -366,21 +366,21 @@ class PlainPrinter(_ctx: Context) extends Printer { /** String representation of symbol's kind. */ def kindString(sym: Symbol): String = { val flags = sym.flagsUNSAFE - if (flags is PackageClass) "package class" - else if (flags is PackageVal) "package" + if (flags.is(PackageClass)) "package class" + else if (flags.is(PackageVal)) "package" else if (sym.isPackageObject) if (sym.isClass) "package object class" else "package object" else if (sym.isAnonymousClass) "anonymous class" - else if (flags is ModuleClass) "module class" - else if (flags is ModuleVal) "module" - else if (flags is Trait) "trait" + else if (flags.is(ModuleClass)) "module class" + else if (flags.is(ModuleVal)) "module" + else if (flags.is(Trait)) "trait" else if (sym.isClass) "class" else if (sym.isType) "type" else if (sym.isGetter) "getter" else if (sym.isSetter) "setter" - else if (flags is Lazy) "lazy value" - else if (flags is Mutable) "variable" + else if (flags.is(Lazy)) "lazy value" + else if (flags.is(Mutable)) "variable" else if (sym.isClassConstructor && sym.isPrimaryConstructor) "primary constructor" else if (sym.isClassConstructor) "constructor" else if (sym.is(Method)) "method" @@ -392,14 +392,14 @@ class PlainPrinter(_ctx: Context) extends Printer { protected def keyString(sym: Symbol): String = { val flags = sym.flagsUNSAFE if (flags.isAll(JavaTrait)) "interface" - else if (flags is Trait) "trait" - else if (flags is Module) "object" + else if (flags.is(Trait)) "trait" + else if (flags.is(Module)) "object" else if (sym.isClass) "class" else if (sym.isType) "type" - else if (flags is Mutable) "var" - else if (flags is Package) "package" - else if (sym is Method) "def" - else if (sym.isTerm && (!(flags is Param))) "val" + else if (flags.is(Mutable)) "var" + else if (flags.is(Package)) "package" + else if (sym.is(Method)) "def" + else if (sym.isTerm && !flags.is(Param)) "val" else "" } @@ -464,7 +464,7 @@ class PlainPrinter(_ctx: Context) extends Printer { else if (ownr.isAnonymousFunction) nextOuter("function") else if (isEmptyPrefix(ownr)) "" else if (ownr.isLocalDummy) showLocation(ownr.owner, "locally defined in") - else if (ownr.isTerm && !ownr.is(Module | Method)) showLocation(ownr, "in the initializer of") + else if (ownr.isTerm && !ownr.isOneOf(Module | Method)) showLocation(ownr, "in the initializer of") else showLocation(ownr, "in") } recur(sym.owner, "") diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index a7de29612c73..f6aa540916bd 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -86,7 +86,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { override protected def fullNameOwner(sym: Symbol): Symbol = { val owner = super.fullNameOwner(sym) - if (owner is ModuleClass) owner.sourceModule else owner + if (owner.is(ModuleClass)) owner.sourceModule else owner } override def toTextRef(tp: SingletonType): Text = controlled { @@ -298,8 +298,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { } def varianceText(mods: untpd.Modifiers) = - if (mods is Covariant) "+" - else if (mods is Contravariant) "-" + if (mods.is(Covariant)) "+" + else if (mods.is(Contravariant)) "-" else "" def argText(arg: Tree): Text = arg match { @@ -344,7 +344,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { case Ident(name) => val txt = tree.typeOpt match { case tp: NamedType if name != nme.WILDCARD => - val pre = if (tp.symbol is JavaStatic) tp.prefix.widen else tp.prefix + val pre = if (tp.symbol.is(JavaStatic)) tp.prefix.widen else tp.prefix toTextPrefix(pre) ~ withPos(selectionString(tp), tree.sourcePos) case _ => toText(name) @@ -549,9 +549,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { def argToText(arg: Tree) = arg match { case arg @ ValDef(name, tpt, _) => val implicitText = - if ((arg.mods is Given)) { contextual = true; "" } - else if ((arg.mods is Erased)) { isErased = true; "" } - else if ((arg.mods is Implicit) && !implicitSeen) { implicitSeen = true; keywordStr("implicit ") } + if ((arg.mods.is(Given))) { contextual = true; "" } + else if ((arg.mods.is(Erased))) { isErased = true; "" } + else if ((arg.mods.is(Implicit)) && !implicitSeen) { implicitSeen = true; keywordStr("implicit ") } else "" implicitText ~ toText(name) ~ optAscription(tpt) case _ => @@ -734,7 +734,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { protected def valDefToText[T >: Untyped](tree: ValDef[T]): Text = { import untpd.{modsDeco => _} dclTextOr(tree) { - modText(tree.mods, tree.symbol, keywordStr(if (tree.mods is Mutable) "var" else "val"), isType = false) ~~ + modText(tree.mods, tree.symbol, keywordStr(if (tree.mods.is(Mutable)) "var" else "val"), isType = false) ~~ valDefText(nameIdText(tree)) ~ optAscription(tree.tpt) ~ withEnclosingDef(tree) { optText(tree.rhs)(" = " ~ _) } } @@ -791,7 +791,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { } protected def templateText(tree: TypeDef, impl: Template): Text = { - val decl = modText(tree.mods, tree.symbol, keywordStr(if ((tree).mods is Trait) "trait" else "class"), isType = true) + val decl = modText(tree.mods, tree.symbol, keywordStr(if (tree.mods.is(Trait)) "trait" else "class"), isType = true) ( decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) } // ~ (if (tree.hasType && printDebug) i"[decls = ${tree.symbol.info.decls}]" else "") // uncomment to enable ) @@ -844,11 +844,11 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { override protected def ParamRefNameString(name: Name): String = name.invariantName.toString - override protected def treatAsTypeParam(sym: Symbol): Boolean = sym is TypeParam + override protected def treatAsTypeParam(sym: Symbol): Boolean = sym.is(TypeParam) override protected def treatAsTypeArg(sym: Symbol): Boolean = sym.isType && (sym.isAll(ProtectedLocal)) && - (sym.allOverriddenSymbols exists (_ is TypeParam)) + (sym.allOverriddenSymbols exists (_.is(TypeParam))) override def toText(sym: Symbol): Text = { if (sym.isImport) @@ -879,9 +879,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { /** String representation of symbol's kind. */ override def kindString(sym: Symbol): String = { val flags = sym.flagsUNSAFE - if (flags is Package) "package" + if (flags.is(Package)) "package" else if (sym.isPackageObject) "package object" - else if (flags is Module) "object" + else if (flags.is(Module)) "object" else if (sym.isClassConstructor) "constructor" else super.kindString(sym) } @@ -901,7 +901,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { super.toTextFlags(sym) else { var flags = sym.flagsUNSAFE - if (flags is TypeParam) flags = flags &~ Protected + if (flags.is(TypeParam)) flags = flags &~ Protected toTextFlags(sym, flags & PrintableFlags(sym.isType)) } diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 51746c5c0020..e66ca764c8fa 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -316,7 +316,7 @@ object messages { import core.Flags._ val maxDist = 3 val decls = site.decls.toList.flatMap { sym => - if (sym.flagsUNSAFE.is(Synthetic | PrivateOrLocal) || sym.isConstructor) Nil + if (sym.flagsUNSAFE.isOneOf(Synthetic | PrivateOrLocal) || sym.isConstructor) Nil else List((sym.name.show, sym)) } diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala index 278529ad8ceb..958707f4ee16 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala @@ -565,7 +565,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder def apiAccess(sym: Symbol): api.Access = { // Symbols which are private[foo] do not have the flag Private set, // but their `privateWithin` exists, see `Parsers#ParserCommon#normalize`. - if (!sym.is(Protected | Private) && !sym.privateWithin.exists) + if (!sym.isOneOf(Protected | Private) && !sym.privateWithin.exists) Constants.public else if (sym.isAll(PrivateLocal)) Constants.privateLocal @@ -589,7 +589,7 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder val abs = sym.is(Abstract) || sym.is(Deferred) || absOver val over = sym.is(Override) || absOver new api.Modifiers(abs, over, sym.is(Final), sym.is(Sealed), - sym.is(ImplicitOrImpliedOrGiven), sym.is(Lazy), sym.is(Macro), sym.isSuperAccessor) + sym.isOneOf(ImplicitOrImpliedOrGiven), sym.is(Lazy), sym.is(Macro), sym.isSuperAccessor) } def apiAnnotations(s: Symbol): List[api.Annotation] = { diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index 70c883bdc241..10b5985cab59 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -1680,7 +1680,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Flags = core.Flags.FlagSet /** Is the given flag set a subset of this flag sets */ - def Flags_is(self: Flags)(that: Flags): Boolean = self.is(that) + def Flags_is(self: Flags)(that: Flags): Boolean = self.isAll(allOf(that)) /** Union of the two flag sets */ def Flags_or(self: Flags)(that: Flags): Flags = self | that diff --git a/compiler/src/dotty/tools/dotc/transform/Bridges.scala b/compiler/src/dotty/tools/dotc/transform/Bridges.scala index e51822c7c4b9..91b595728be8 100644 --- a/compiler/src/dotty/tools/dotc/transform/Bridges.scala +++ b/compiler/src/dotty/tools/dotc/transform/Bridges.scala @@ -29,7 +29,7 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont override def parents = Array(root.superClass) override def exclude(sym: Symbol) = - !sym.is(MethodOrModule) || + !sym.isOneOf(MethodOrModule) || isImplicitShortcut(sym) || super.exclude(sym) } diff --git a/compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala b/compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala index a44eac861cea..a573618d90d1 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala @@ -63,7 +63,7 @@ class CheckReentrant extends MiniPhase { i"""possible data race involving globally reachable ${sym.showLocated}: ${sym.info} | use -Ylog:checkReentrant+ to find out more about why the variable is reachable.""") shared += sym - } else if (!sym.is(Method) || sym.is(Accessor | ParamAccessor)) { + } else if (!sym.is(Method) || sym.isOneOf(Accessor | ParamAccessor)) { scanning(sym) { sym.info.widenExpr.classSymbols.foreach(addVars) } diff --git a/compiler/src/dotty/tools/dotc/transform/Constructors.scala b/compiler/src/dotty/tools/dotc/transform/Constructors.scala index 32aad5c004f0..f8ea24f80d05 100644 --- a/compiler/src/dotty/tools/dotc/transform/Constructors.scala +++ b/compiler/src/dotty/tools/dotc/transform/Constructors.scala @@ -99,7 +99,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase = */ override def checkPostCondition(tree: tpd.Tree)(implicit ctx: Context): Unit = { def emptyRhsOK(sym: Symbol) = - sym.is(LazyOrDeferred) || sym.isConstructor && sym.owner.isAll(NoInitsTrait) + sym.isOneOf(LazyOrDeferred) || sym.isConstructor && sym.owner.isAll(NoInitsTrait) tree match { case tree: ValDef if tree.symbol.exists && tree.symbol.owner.isClass && !tree.symbol.is(Lazy) && !tree.symbol.hasAnnotation(defn.ScalaStaticAnnot) => assert(tree.rhs.isEmpty, i"$tree: initializer should be moved to constructors") @@ -148,7 +148,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase = override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match { case Ident(_) | Select(This(_), _) => var sym = tree.symbol - if (sym is (ParamAccessor, butNot = Mutable)) sym = sym.subst(accessors, paramSyms) + if (sym.is(ParamAccessor, butNot = Mutable)) sym = sym.subst(accessors, paramSyms) if (sym.owner.isConstructor) ref(sym).withSpan(tree.span) else tree case Apply(fn, Nil) => val fn1 = transform(fn) diff --git a/compiler/src/dotty/tools/dotc/transform/ElimErasedValueType.scala b/compiler/src/dotty/tools/dotc/transform/ElimErasedValueType.scala index b4bae8a4a18b..699105fabb24 100644 --- a/compiler/src/dotty/tools/dotc/transform/ElimErasedValueType.scala +++ b/compiler/src/dotty/tools/dotc/transform/ElimErasedValueType.scala @@ -30,7 +30,7 @@ class ElimErasedValueType extends MiniPhase with InfoTransformer { thisPhase => override def runsAfter: Set[String] = Set(Erasure.name) def transformInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type = sym match { - case sym: ClassSymbol if sym is ModuleClass => + case sym: ClassSymbol if sym.is(ModuleClass) => sym.companionClass match { case origClass: ClassSymbol if isDerivedValueClass(origClass) => val cinfo = tp.asInstanceOf[ClassInfo] diff --git a/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala b/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala index 625be403a508..a7f067e561ef 100644 --- a/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala +++ b/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala @@ -43,9 +43,9 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase => ref1 } - override def mayChange(sym: Symbol)(implicit ctx: Context): Boolean = sym is Method + override def mayChange(sym: Symbol)(implicit ctx: Context): Boolean = sym.is(Method) - private def overridesJava(sym: Symbol)(implicit ctx: Context) = sym.allOverriddenSymbols.exists(_ is JavaDefined) + private def overridesJava(sym: Symbol)(implicit ctx: Context) = sym.allOverriddenSymbols.exists(_.is(JavaDefined)) private def elimRepeated(tp: Type)(implicit ctx: Context): Type = tp.stripTypeVar match { case tp @ MethodTpe(paramNames, paramTypes, resultType) => diff --git a/compiler/src/dotty/tools/dotc/transform/Erasure.scala b/compiler/src/dotty/tools/dotc/transform/Erasure.scala index 8cd1854c4a37..551429b3b959 100644 --- a/compiler/src/dotty/tools/dotc/transform/Erasure.scala +++ b/compiler/src/dotty/tools/dotc/transform/Erasure.scala @@ -76,7 +76,7 @@ class Erasure extends Phase with DenotTransformer { val oldFlags = ref.flags val newFlags = if (oldSymbol.is(Flags.TermParam) && isCompacted(oldSymbol.owner)) oldFlags &~ Flags.Param - else oldFlags &~ Flags.HasDefaultParams // HasDefaultParams needs to be dropped because overriding might become overloading + else oldFlags &~ Flags.HasDefaultParamsFlags // HasDefaultParamsFlags needs to be dropped because overriding might become overloading // TODO: define derivedSymDenotation? if ((oldSymbol eq newSymbol) && (oldOwner eq newOwner) && (oldName eq newName) && (oldInfo eq newInfo) && (oldFlags == newFlags)) @@ -461,7 +461,7 @@ object Erasure { def adaptIfSuper(qual: Tree): Tree = qual match { case Super(thisQual, untpd.EmptyTypeIdent) => val SuperType(thisType, supType) = qual.tpe - if (sym.owner is Flags.Trait) + if (sym.owner.is(Flags.Trait)) cpy.Super(qual)(thisQual, untpd.Ident(sym.owner.asClass.name)) .withType(SuperType(thisType, sym.owner.typeRef)) else @@ -750,5 +750,5 @@ object Erasure { } private def takesBridges(sym: Symbol)(implicit ctx: Context): Boolean = - sym.isClass && !sym.is(Flags.Trait | Flags.Package) + sym.isClass && !sym.isOneOf(Flags.Trait | Flags.Package) } diff --git a/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala b/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala index 7c8ae4cd6c8a..1376253e978c 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala @@ -46,7 +46,7 @@ class ExpandPrivate extends MiniPhase with IdentityDenotTransformer { thisPhase def hasWeakerAccess(other: Symbol) = { // public > protected > /* default */ > private if (sym.is(Private)) other.is(Private) - else if (sym.is(Protected)) other.is(Protected | Private) + else if (sym.is(Protected)) other.isOneOf(Protected | Private) else true // sym is public } val fail = sym.allOverriddenSymbols.findSymbol(x => !hasWeakerAccess(x)) diff --git a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala index 3900474bf1cd..c9e64ec89797 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala @@ -138,7 +138,7 @@ object ExplicitOuter { /** The outer accessor and potentially outer param accessor needed for class `cls` */ private def newOuterAccessors(cls: ClassSymbol)(implicit ctx: Context) = - newOuterAccessor(cls, cls) :: (if (cls is Trait) Nil else newOuterParamAccessor(cls) :: Nil) + newOuterAccessor(cls, cls) :: (if (cls.is(Trait)) Nil else newOuterParamAccessor(cls) :: Nil) /** Scala 2.x and Dotty don't always agree on what should be the type of the outer parameter, * so we replicate the old behavior when passing arguments to methods coming from Scala 2.x. @@ -236,8 +236,8 @@ object ExplicitOuter { */ def outerAccessor(cls: ClassSymbol)(implicit ctx: Context): Symbol = if (cls.isStatic) NoSymbol // fast return to avoid scanning package decls - else cls.info.member(outerAccName(cls)).suchThat(_ is OuterAccessor).symbol orElse - cls.info.decls.find(_ is OuterAccessor) + else cls.info.member(outerAccName(cls)).suchThat(_.is(OuterAccessor)).symbol orElse + cls.info.decls.find(_.is(OuterAccessor)) /** Class has an outer accessor. Can be called only after phase ExplicitOuter. */ private def hasOuter(cls: ClassSymbol)(implicit ctx: Context): Boolean = @@ -259,7 +259,7 @@ object ExplicitOuter { if (ref.prefix ne NoPrefix) !ref.symbol.isStatic && isOuterRef(ref.prefix) else ( - (ref.symbol is Hoistable) && + ref.symbol.isOneOf(HoistableFlags) && // ref.symbol will be placed in enclosing class scope by LambdaLift, so it might need // an outer path then. isOuterSym(ref.symbol.owner.enclosingClass) @@ -291,7 +291,7 @@ object ExplicitOuter { } } - private final val Hoistable = Method | Lazy | Module + private final val HoistableFlags = Method | Lazy | Module /** The outer prefix implied by type `tpe` */ private def outerPrefix(tpe: Type)(implicit ctx: Context): Type = tpe match { diff --git a/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala b/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala index 9ebd8e98b203..490479c8d953 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala @@ -53,7 +53,7 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete override def changesMembers: Boolean = true // the phase adds extension methods override def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation = ref match { - case moduleClassSym: ClassDenotation if moduleClassSym is ModuleClass => + case moduleClassSym: ClassDenotation if moduleClassSym.is(ModuleClass) => moduleClassSym.linkedClass match { case valueClass: ClassSymbol if isDerivedValueClass(valueClass) => val cinfo = moduleClassSym.classInfo @@ -101,7 +101,7 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete ref1 = ref.copySymDenotation() ref1.removeAnnotation(defn.TailrecAnnot) } - else if (ref.isConstructor && isDerivedValueClass(ref.owner) && ref.is(AccessFlags)) { + else if (ref.isConstructor && isDerivedValueClass(ref.owner) && ref.isOneOf(AccessFlags)) { ref1 = ref.copySymDenotation() ref1.resetFlag(AccessFlags) } diff --git a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala index 84d6449ee747..8943477df2de 100644 --- a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala +++ b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala @@ -71,7 +71,7 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase => */ def reorder(stats: List[Tree], revPrefix: List[Tree]): List[Tree] = stats match { case (stat: TypeDef) :: stats1 if stat.symbol.isClass => - if (stat.symbol is Flags.Module) { + if (stat.symbol.is(Flags.Module)) { def pushOnTop(xs: List[Tree], ys: List[Tree]): List[Tree] = (ys /: xs)((ys, x) => x :: ys) moduleClassDefs += (stat.name -> stat) diff --git a/compiler/src/dotty/tools/dotc/transform/Flatten.scala b/compiler/src/dotty/tools/dotc/transform/Flatten.scala index afbb854f542b..941e7ca146f0 100644 --- a/compiler/src/dotty/tools/dotc/transform/Flatten.scala +++ b/compiler/src/dotty/tools/dotc/transform/Flatten.scala @@ -41,14 +41,14 @@ class Flatten extends MiniPhase with SymTransformer { ctx.fresh.updateStore(LiftedDefs, new mutable.ListBuffer[Tree]) private def liftIfNested(tree: Tree)(implicit ctx: Context) = - if (ctx.owner is Package) tree + if (ctx.owner.is(Package)) tree else { transformFollowing(tree).foreachInThicket(liftedDefs += _) EmptyTree } override def transformStats(stats: List[Tree])(implicit ctx: Context): List[Tree] = - if (ctx.owner is Package) { + if (ctx.owner.is(Package)) { val liftedStats = stats ++ liftedDefs liftedDefs.clear() liftedStats diff --git a/compiler/src/dotty/tools/dotc/transform/Getters.scala b/compiler/src/dotty/tools/dotc/transform/Getters.scala index e14a7b8779db..1e86d9f07f1b 100644 --- a/compiler/src/dotty/tools/dotc/transform/Getters.scala +++ b/compiler/src/dotty/tools/dotc/transform/Getters.scala @@ -53,8 +53,8 @@ class Getters extends MiniPhase with SymTransformer { override def transformSym(d: SymDenotation)(implicit ctx: Context): SymDenotation = { def noGetterNeeded = - d.is(NoGetterNeeded) || - d.isAll(PrivateLocal) && !d.owner.is(Trait) && !isDerivedValueClass(d.owner) && !d.is(Flags.Lazy) || + d.isOneOf(NoGetterNeededFlags) || + d.isAll(PrivateLocal) && !d.owner.is(Trait) && !isDerivedValueClass(d.owner) && !d.is(Lazy) || d.is(Module) && d.isStatic || d.hasAnnotation(defn.ScalaStaticAnnot) || d.isSelfSym @@ -79,13 +79,13 @@ class Getters extends MiniPhase with SymTransformer { } d1 } - private val NoGetterNeeded = Method | Param | JavaDefined | JavaStatic + private val NoGetterNeededFlags = Method | Param | JavaDefined | JavaStatic override def transformValDef(tree: ValDef)(implicit ctx: Context): Tree = - if (tree.symbol is Method) DefDef(tree.symbol.asTerm, tree.rhs).withSpan(tree.span) else tree + if (tree.symbol.is(Method)) DefDef(tree.symbol.asTerm, tree.rhs).withSpan(tree.span) else tree override def transformAssign(tree: Assign)(implicit ctx: Context): Tree = - if (tree.lhs.symbol is Method) tree.lhs.becomes(tree.rhs).withSpan(tree.span) else tree + if (tree.lhs.symbol.is(Method)) tree.lhs.becomes(tree.rhs).withSpan(tree.span) else tree } object Getters { diff --git a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala index bfb1b689a168..59c3b50846ce 100644 --- a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala +++ b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala @@ -67,7 +67,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer { def transformLazyVal(tree: ValOrDefDef)(implicit ctx: Context): Tree = { val sym = tree.symbol - if (!(sym is Lazy) || + if (!sym.is(Lazy) || sym.owner.is(Trait) || // val is accessor, lazy field will be implemented in subclass (sym.isStatic && sym.is(Module, butNot = Method))) // static module vals are implemented in the JVM by lazy loading tree @@ -389,7 +389,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer { val offsetById = offsetName(id) if (ord != 0) { // there are unused bits in already existing flag offsetSymbol = claz.info.decl(offsetById) - .suchThat(sym => (sym is Synthetic) && sym.isTerm) + .suchThat(sym => sym.is(Synthetic) && sym.isTerm) .symbol.asTerm } else { // need to create a new flag offsetSymbol = ctx.newSymbol(claz, offsetById, Synthetic, defn.LongType).enteredAfter(this) diff --git a/compiler/src/dotty/tools/dotc/transform/MacroTransform.scala b/compiler/src/dotty/tools/dotc/transform/MacroTransform.scala index 8ec26acfcf5e..d567d48461e4 100644 --- a/compiler/src/dotty/tools/dotc/transform/MacroTransform.scala +++ b/compiler/src/dotty/tools/dotc/transform/MacroTransform.scala @@ -33,7 +33,7 @@ abstract class MacroTransform extends Phase { protected def localCtx(tree: Tree)(implicit ctx: Context): FreshContext = { val sym = tree.symbol - val owner = if (sym is PackageVal) sym.moduleClass else sym + val owner = if (sym.is(PackageVal)) sym.moduleClass else sym ctx.fresh.setTree(tree).setOwner(owner) } diff --git a/compiler/src/dotty/tools/dotc/transform/MegaPhase.scala b/compiler/src/dotty/tools/dotc/transform/MegaPhase.scala index 0753f260d6dc..b93be0f09a95 100644 --- a/compiler/src/dotty/tools/dotc/transform/MegaPhase.scala +++ b/compiler/src/dotty/tools/dotc/transform/MegaPhase.scala @@ -215,7 +215,7 @@ class MegaPhase(val miniPhases: Array[MiniPhase]) extends Phase { def transformTree(tree: Tree, start: Int)(implicit ctx: Context): Tree = { def localContext(implicit ctx: Context) = { val sym = tree.symbol - val owner = if (sym is PackageVal) sym.moduleClass else sym + val owner = if (sym.is(PackageVal)) sym.moduleClass else sym ctx.fresh.setOwner(owner) } diff --git a/compiler/src/dotty/tools/dotc/transform/Memoize.scala b/compiler/src/dotty/tools/dotc/transform/Memoize.scala index 6689729d8502..bc25654757fb 100644 --- a/compiler/src/dotty/tools/dotc/transform/Memoize.scala +++ b/compiler/src/dotty/tools/dotc/transform/Memoize.scala @@ -80,7 +80,7 @@ class Memoize extends MiniPhase with IdentityDenotTransformer { thisPhase => ctx.newSymbol( owner = ctx.owner, name = sym.name.asTermName.fieldName, - flags = Private | (if (sym is StableRealizable) EmptyFlags else Mutable), + flags = Private | (if (sym.is(StableRealizable)) EmptyFlags else Mutable), info = fieldType, coord = tree.span ).withAnnotationsCarrying(sym, defn.FieldMetaAnnot) diff --git a/compiler/src/dotty/tools/dotc/transform/Mixin.scala b/compiler/src/dotty/tools/dotc/transform/Mixin.scala index 60f3b60d130d..119bdfa84b90 100644 --- a/compiler/src/dotty/tools/dotc/transform/Mixin.scala +++ b/compiler/src/dotty/tools/dotc/transform/Mixin.scala @@ -119,7 +119,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase => override def transformSym(sym: SymDenotation)(implicit ctx: Context): SymDenotation = if (sym.is(Accessor, butNot = Deferred) && sym.owner.is(Trait)) { val sym1 = - if (sym is Lazy) sym + if (sym.is(Lazy)) sym else sym.copySymDenotation(initFlags = sym.flags &~ ParamAccessor | Deferred) sym1.ensureNotPrivate } @@ -131,7 +131,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase => sym private def initializer(sym: Symbol)(implicit ctx: Context): TermSymbol = { - if (sym is Lazy) sym + if (sym.is(Lazy)) sym else { val initName = InitializerName(sym.name.asTermName) sym.owner.info.decl(initName).symbol @@ -153,7 +153,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase => def traitDefs(stats: List[Tree]): List[Tree] = { val initBuf = new mutable.ListBuffer[Tree] stats.flatMap({ - case stat: DefDef if stat.symbol.isGetter && !stat.rhs.isEmpty && !stat.symbol.is(Flags.Lazy) => + case stat: DefDef if stat.symbol.isGetter && !stat.rhs.isEmpty && !stat.symbol.is(Lazy) => // make initializer that has all effects of previous getter, // replace getter rhs with empty tree. val vsym = stat.symbol @@ -206,8 +206,8 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase => } } - def was(sym: Symbol, flags: FlagSet) = - ctx.atPhase(thisPhase) { implicit ctx => sym is flags } + def wasOneOf(sym: Symbol, flags: FlagSet) = + ctx.atPhase(thisPhase) { implicit ctx => sym.isOneOf(flags) } def traitInits(mixin: ClassSymbol): List[Tree] = { var argNum = 0 @@ -227,14 +227,14 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase => EmptyTree } - for (getter <- mixin.info.decls.toList if getter.isGetter && !was(getter, Deferred)) yield { + for (getter <- mixin.info.decls.toList if getter.isGetter && !wasOneOf(getter, Deferred)) yield { val isScala2x = mixin.is(Scala2x) def default = Underscore(getter.info.resultType) def initial = transformFollowing(superRef(initializer(getter)).appliedToNone) if (isCurrent(getter) || getter.name.is(ExpandedName)) { val rhs = - if (was(getter, ParamAccessor)) + if (wasOneOf(getter, ParamAccessor)) nextArgument() else if (isScala2x) { if (getter.is(Lazy, butNot = Module)) @@ -249,13 +249,13 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase => // transformFollowing call is needed to make memoize & lazy vals run transformFollowing(DefDef(mkForwarderSym(getter.asTerm), rhs)) } - else if (isScala2x || was(getter, ParamAccessor | Lazy)) EmptyTree + else if (isScala2x || wasOneOf(getter, ParamAccessor | Lazy)) EmptyTree else initial } } def setters(mixin: ClassSymbol): List[Tree] = - for (setter <- mixin.info.decls.filter(setr => setr.isSetter && !was(setr, Deferred))) + for (setter <- mixin.info.decls.filter(setr => setr.isSetter && !wasOneOf(setr, Deferred))) yield transformFollowing(DefDef(mkForwarderSym(setter.asTerm), unitLiteral.withSpan(cls.span))) def mixinForwarders(mixin: ClassSymbol): List[Tree] = @@ -272,7 +272,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase => else impl.constr, parents = impl.parents.map(p => TypeTree(p.tpe).withSpan(p.span)), body = - if (cls is Trait) traitDefs(impl.body) + if (cls.is(Trait)) traitDefs(impl.body) else { val mixInits = mixins.flatMap { mixin => flatten(traitInits(mixin)) ::: superCallOpt(mixin) ::: setters(mixin) ::: mixinForwarders(mixin) diff --git a/compiler/src/dotty/tools/dotc/transform/MixinOps.scala b/compiler/src/dotty/tools/dotc/transform/MixinOps.scala index 532a08aecea1..9461da6e9417 100644 --- a/compiler/src/dotty/tools/dotc/transform/MixinOps.scala +++ b/compiler/src/dotty/tools/dotc/transform/MixinOps.scala @@ -55,7 +55,7 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont def needsMixinForwarder(meth: Symbol): Boolean = { lazy val competingMethods = competingMethodsIterator(meth).toList - def needsDisambiguation = competingMethods.exists(x=> !(x is Deferred)) // multiple implementations are available + def needsDisambiguation = competingMethods.exists(x=> !x.is(Deferred)) // multiple implementations are available def hasNonInterfaceDefinition = competingMethods.exists(!_.owner.is(Trait)) // there is a definition originating from class !meth.isConstructor && meth.is(Method, butNot = PrivateOrAccessorOrDeferred) && diff --git a/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala b/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala index d13a102a9713..794539d7fa1f 100644 --- a/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala +++ b/compiler/src/dotty/tools/dotc/transform/ParamForwarding.scala @@ -48,7 +48,7 @@ class ParamForwarding(thisPhase: DenotTransformer) { * } */ val candidate = sym.owner.asClass.superClass - .info.decl(sym.name).suchThat(_ is (ParamAccessor, butNot = Mutable)).symbol + .info.decl(sym.name).suchThat(_.is(ParamAccessor, butNot = Mutable)).symbol if (candidate.isAccessibleFrom(currentClass.thisType, superAccess = true)) candidate else if (candidate.exists) inheritedAccessor(candidate) else NoSymbol diff --git a/compiler/src/dotty/tools/dotc/transform/Pickler.scala b/compiler/src/dotty/tools/dotc/transform/Pickler.scala index d50087f534ef..71049da316e2 100644 --- a/compiler/src/dotty/tools/dotc/transform/Pickler.scala +++ b/compiler/src/dotty/tools/dotc/transform/Pickler.scala @@ -41,7 +41,7 @@ class Pickler extends Phase { /** Drop any elements of this list that are linked module classes of other elements in the list */ private def dropCompanionModuleClasses(clss: List[ClassSymbol])(implicit ctx: Context): List[ClassSymbol] = { val companionModuleClasses = - clss.filterNot(_ is Module).map(_.linkedClass).filterNot(_.unforcedIsAbsent) + clss.filterNot(_.is(Module)).map(_.linkedClass).filterNot(_.unforcedIsAbsent) clss.filterNot(companionModuleClasses.contains) } diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala index d4fb2a1ca6db..a15e192fc6f3 100644 --- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala +++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala @@ -100,7 +100,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase private def transformAnnot(annot: Tree)(implicit ctx: Context): Tree = { val saved = inJavaAnnot - inJavaAnnot = annot.symbol is JavaDefined + inJavaAnnot = annot.symbol.is(JavaDefined) if (inJavaAnnot) checkValidJavaAnnotation(annot) try transform(annot) finally inJavaAnnot = saved diff --git a/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala b/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala index 51f494c4d951..b921bdc57e9b 100644 --- a/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala +++ b/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala @@ -27,7 +27,7 @@ class RenameLifted extends MiniPhase with SymTransformer { * - if it is a lifted method */ private def needsRefresh(sym: Symbol)(implicit ctx: Context): Boolean = - (sym.isClass || sym.is(Private | Method | JavaStatic)) && sym.name.is(UniqueName) + (sym.isClass || sym.isOneOf(Private | Method | JavaStatic)) && sym.name.is(UniqueName) /** Refreshes the number of the name based on the full name of the symbol */ private def refreshedName(sym: Symbol)(implicit ctx: Context): Name = { diff --git a/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala b/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala index 0a9d643a4848..90aad9550375 100644 --- a/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala +++ b/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala @@ -67,7 +67,7 @@ class SuperAccessors(thisPhase: DenotTransformer) { val sym = sel.symbol val clazz = qual.symbol.asClass var superName = SuperAccessorName(name.asTermName) - if (clazz is Trait) superName = superName.expandedName(clazz) + if (clazz.is(Trait)) superName = superName.expandedName(clazz) val superInfo = sel.tpe.widenSingleton.ensureMethodic val accRange = sel.span.focus @@ -75,14 +75,14 @@ class SuperAccessors(thisPhase: DenotTransformer) { .suchThat(_.signature == superInfo.signature).symbol .orElse { ctx.debuglog(s"add super acc ${sym.showLocated} to $clazz") - val maybeDeferred = if (clazz is Trait) Deferred else EmptyFlags + val maybeDeferred = if (clazz.is(Trait)) Deferred else EmptyFlags val acc = ctx.newSymbol( clazz, superName, Artifact | Method | maybeDeferred, superInfo, coord = accRange).enteredAfter(thisPhase) // Diagnostic for SI-7091 if (!accDefs.contains(clazz)) ctx.error( - s"Internal error: unable to store accessor definition in ${clazz}. clazz.hasPackageFlag=${clazz is Package}. Accessor required for ${sel} (${sel.show})", + s"Internal error: unable to store accessor definition in ${clazz}. clazz.hasPackageFlag=${clazz.is(Package)}. Accessor required for ${sel} (${sel.show})", sel.sourcePos) else accDefs(clazz) += DefDef(acc, EmptyTree).withSpan(accRange) acc @@ -105,11 +105,11 @@ class SuperAccessors(thisPhase: DenotTransformer) { ctx.error(s"super may be not be used on ${sym.underlyingSymbol}", sel.sourcePos) else if (isDisallowed(sym)) ctx.error(s"super not allowed here: use this.${sel.name} instead", sel.sourcePos) - else if (sym is Deferred) { + else if (sym.is(Deferred)) { val member = sym.overridingSymbol(clazz.asClass) if (!mix.name.isEmpty || !member.exists || - !((member is AbsOverride) && member.isIncompleteIn(clazz))) + !(member.is(AbsOverride) && member.isIncompleteIn(clazz))) ctx.error( i"${sym.showLocated} is accessed from super. It may not be abstract unless it is overridden by a member declared `abstract' and `override'", sel.sourcePos) @@ -122,7 +122,7 @@ class SuperAccessors(thisPhase: DenotTransformer) { // scala/bug#4989 Check if an intermediate class between `clazz` and `sym.owner` redeclares the method as abstract. for (intermediateClass <- clazz.info.baseClasses.tail.takeWhile(_ != sym.owner)) { val overriding = sym.overridingSymbol(intermediateClass) - if ((overriding is (Deferred, butNot = AbsOverride)) && !(overriding.owner is Trait)) + if (overriding.is(Deferred, butNot = AbsOverride) && !overriding.owner.is(Trait)) ctx.error( s"${sym.showLocated} cannot be directly accessed from ${clazz} because ${overriding.owner} redeclares it as abstract", sel.sourcePos) @@ -149,7 +149,7 @@ class SuperAccessors(thisPhase: DenotTransformer) { } } if (name.isTermName && mix.name.isEmpty && - ((clazz is Trait) || clazz != ctx.owner.enclosingClass || !validCurrentClass)) + (clazz.is(Trait) || clazz != ctx.owner.enclosingClass || !validCurrentClass)) superAccessorCall(sel)(ctx.withPhase(thisPhase.next)) else sel } @@ -205,7 +205,7 @@ class SuperAccessors(thisPhase: DenotTransformer) { else { val (params, rest) = impl.body span { case td: TypeDef => !td.isClassDef - case vd: ValOrDefDef => vd.symbol.flags is ParamAccessor + case vd: ValOrDefDef => vd.symbol.flags.is(ParamAccessor) case _ => false } cpy.Template(impl)(body = params ++ accessors ++ rest) diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index 2695f1486487..824ec7db8b01 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -41,7 +41,7 @@ class SymUtils(val self: Symbol) extends AnyVal { * The empty list if `self` is a trait. */ def mixins(implicit ctx: Context): List[ClassSymbol] = { - if (self is Trait) Nil + if (self.is(Trait)) Nil else directlyInheritedTraits } @@ -142,10 +142,10 @@ class SymUtils(val self: Symbol) extends AnyVal { } def accessorNamed(name: TermName)(implicit ctx: Context): Symbol = - self.owner.info.decl(name).suchThat(_ is Accessor).symbol + self.owner.info.decl(name).suchThat(_.is(Accessor)).symbol def caseAccessors(implicit ctx: Context): List[Symbol] = - self.info.decls.filter(_ is CaseAccessor) + self.info.decls.filter(_.is(CaseAccessor)) def getter(implicit ctx: Context): Symbol = if (self.isGetter) self else accessorNamed(self.asTerm.name.getterName) diff --git a/compiler/src/dotty/tools/dotc/transform/TransformByNameApply.scala b/compiler/src/dotty/tools/dotc/transform/TransformByNameApply.scala index c58c19c834a1..9052d173d795 100644 --- a/compiler/src/dotty/tools/dotc/transform/TransformByNameApply.scala +++ b/compiler/src/dotty/tools/dotc/transform/TransformByNameApply.scala @@ -27,7 +27,7 @@ abstract class TransformByNameApply extends MiniPhase { thisPhase: DenotTransfor /** If denotation had an ExprType before, it now gets a function type */ protected def exprBecomesFunction(symd: SymDenotation)(implicit ctx: Context): Boolean = - (symd is Param) || (symd is (ParamAccessor, butNot = Method)) + (symd.is(Param)) || symd.is(ParamAccessor, butNot = Method) protected def isByNameRef(tree: Tree)(implicit ctx: Context): Boolean = { val origDenot = originalDenotation(tree) diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index 7c8fda62a03d..843544996acb 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -46,7 +46,7 @@ class TreeChecker extends Phase with SymTransformer { def isValidJVMMethodName(name: Name): Boolean = name.toString.forall(isValidJVMMethodChar) - val NoSuperClass: FlagSet = Trait | Package + val NoSuperClassFlags: FlagSet = Trait | Package def testDuplicate(sym: Symbol, registry: mutable.Map[String, Symbol], typ: String)(implicit ctx: Context): Unit = { val name = sym.fullName.mangledString @@ -70,7 +70,7 @@ class TreeChecker extends Phase with SymTransformer { if (sym.isClass && !sym.isAbsent) { val validSuperclass = sym.isPrimitiveValueClass || defn.syntheticCoreClasses.contains(sym) || - (sym eq defn.ObjectClass) || (sym is NoSuperClass) || (sym.asClass.superClass.exists) || + (sym eq defn.ObjectClass) || sym.isOneOf(NoSuperClassFlags) || (sym.asClass.superClass.exists) || sym.isRefinementClass assert(validSuperclass, i"$sym has no superclass set") @@ -391,7 +391,7 @@ class TreeChecker extends Phase with SymTransformer { ddef.vparamss.foreach(_.foreach { vparam => assert(vparam.symbol.is(Param), s"Parameter ${vparam.symbol} of ${sym.fullName} does not have flag `Param` set") - assert(!vparam.symbol.is(AccessFlags), + assert(!vparam.symbol.isOneOf(AccessFlags), s"Parameter ${vparam.symbol} of ${sym.fullName} has invalid flag(s): ${(vparam.symbol.flags & AccessFlags).flagsString}") }) diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index fb3f0c973274..30f98ab8a668 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -525,7 +525,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { val dealiasedTp = tp.dealias val res = (tp.classSymbol.is(Sealed) && - tp.classSymbol.is(AbstractOrTrait) && + tp.classSymbol.isOneOf(AbstractOrTrait) && !tp.classSymbol.hasAnonymousChild && tp.classSymbol.children.nonEmpty ) || dealiasedTp.isInstanceOf[OrType] || diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 418c7dafd516..258d4e092d8d 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -471,7 +471,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => } } val getterPrefix = - if ((meth is Synthetic) && meth.name == nme.apply) nme.CONSTRUCTOR else meth.name + if ((meth.is(Synthetic)) && meth.name == nme.apply) nme.CONSTRUCTOR else meth.name def getterName = DefaultGetterName(getterPrefix, n) if (!meth.hasDefaultParams) EmptyTree @@ -1218,8 +1218,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic => if (sym1 == sym2) 0 else if (sym1 isSubClass sym2) 1 else if (sym2 isSubClass sym1) -1 - else if (sym2 is Module) compareOwner(sym1, sym2.companionClass) - else if (sym1 is Module) compareOwner(sym1.companionClass, sym2) + else if (sym2.is(Module)) compareOwner(sym1, sym2.companionClass) + else if (sym1.is(Module)) compareOwner(sym1.companionClass, sym2) else 0 /** Compare to alternatives of an overloaded call or an implicit search. diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 2e240c3ebc95..54bc085489a9 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -137,7 +137,7 @@ object Checking { tp.underlyingClassRef(refinementOK = false) match { case tref: TypeRef => val cls = tref.symbol - if (cls.is(AbstractOrTrait)) + if (cls.isOneOf(AbstractOrTrait)) ctx.error(CantInstantiateAbstractClassOrTrait(cls, isTrait = cls.is(Trait)), posd.sourcePos) if (!cls.is(Module)) { // Create a synthetic singleton type instance, and check whether @@ -389,7 +389,7 @@ object Checking { def fail(msg: Message) = ctx.error(msg, sym.sourcePos) def checkWithDeferred(flag: FlagSet) = - if (sym.is(flag)) + if (sym.isOneOf(flag)) fail(AbstractMemberMayNotHaveModifier(sym, flag)) def checkNoConflict(flag1: FlagSet, flag2: FlagSet, msg: => String) = if (sym.isAll(allOf(flag1, flag2))) fail(msg) @@ -405,7 +405,7 @@ object Checking { )) fail(ParamsNoInline(sym.owner)) - if (sym.is(ImplicitOrImplied)) { + if (sym.isOneOf(ImplicitOrImplied)) { if (sym.owner.is(Package)) fail(TopLevelCantBeImplicit(sym)) if (sym.isType) @@ -418,7 +418,7 @@ object Checking { if (sym.is(Trait) && sym.is(Final)) fail(TraitsMayNotBeFinal(sym)) // Skip ModuleVal since the annotation will also be on the ModuleClass - if (sym.hasAnnotation(defn.TailrecAnnot) && !sym.is(Method | ModuleVal)) + if (sym.hasAnnotation(defn.TailrecAnnot) && !sym.isOneOf(Method | ModuleVal)) fail(TailrecNotApplicable(sym)) if (sym.hasAnnotation(defn.NativeAnnot)) { if (!sym.is(Deferred)) @@ -439,15 +439,15 @@ object Checking { checkCombination(Private, Override) checkCombination(Lazy, Inline) checkNoConflict(Lazy, ParamAccessor, s"parameter may not be `lazy`") - if (sym.is(Inline)) checkApplicable(Inline, sym.isTerm && !sym.is(Mutable | Module)) - if (sym.is(Lazy)) checkApplicable(Lazy, !sym.is(Method | Mutable)) + if (sym.is(Inline)) checkApplicable(Inline, sym.isTerm && !sym.isOneOf(Mutable | Module)) + if (sym.is(Lazy)) checkApplicable(Lazy, !sym.isOneOf(Method | Mutable)) if (sym.isType && !sym.is(Deferred)) for (cls <- sym.allOverriddenSymbols.filter(_.isClass)) { fail(CannotHaveSameNameAs(sym, cls, CannotHaveSameNameAs.CannotBeOverridden)) sym.setFlag(Private) // break the overriding relationship by making sym Private } if (sym.is(Erased)) - checkApplicable(Erased, !sym.is(MutableOrLazy)) + checkApplicable(Erased, !sym.isOneOf(MutableOrLazy)) } /** Check the type signature of the symbol `M` defined by `tree` does not refer @@ -679,7 +679,7 @@ trait Checking { def checkClassType(tp: Type, pos: SourcePosition, traitReq: Boolean, stablePrefixReq: Boolean)(implicit ctx: Context): Type = tp.underlyingClassRef(refinementOK = false) match { case tref: TypeRef => - if (traitReq && !(tref.symbol is Trait)) ctx.error(TraitIsExpected(tref.symbol), pos) + if (traitReq && !tref.symbol.is(Trait)) ctx.error(TraitIsExpected(tref.symbol), pos) if (stablePrefixReq && ctx.phase <= ctx.refchecksPhase) checkStable(tref.prefix, pos) tp case _ => @@ -719,7 +719,7 @@ trait Checking { def checkImplicitConversionUseOK(sym: Symbol, posd: Positioned)(implicit ctx: Context): Unit = if (sym.exists) { val conv = - if (sym.is(ImplicitOrGiven)) sym + if (sym.isOneOf(ImplicitOrGiven)) sym else { assert(sym.name == nme.apply) sym.owner @@ -884,9 +884,9 @@ trait Checking { if (decl is Synthetic) doubleDefError(other, decl) else doubleDefError(decl, other) } - if ((decl is HasDefaultParams) && (other is HasDefaultParams)) { + if (decl.isOneOf(HasDefaultParamsFlags) && other.isOneOf(HasDefaultParamsFlags)) { ctx.error(em"two or more overloaded variants of $decl have default arguments", decl.sourcePos) - decl resetFlag HasDefaultParams + decl.resetFlag(HasDefaultParamsFlags) } } if (!excludeFromDoubleDeclCheck(decl)) @@ -903,7 +903,7 @@ trait Checking { def checkParentCall(call: Tree, caller: ClassSymbol)(implicit ctx: Context): Unit = if (!ctx.isAfterTyper) { val called = call.tpe.classSymbol - if (caller is Trait) + if (caller.is(Trait)) ctx.error(i"$caller may not call constructor of $called", call.sourcePos) else if (called.is(Trait) && !caller.mixins.contains(called)) ctx.error(i"""$called is already implemented by super${caller.superClass}, @@ -961,7 +961,7 @@ trait Checking { */ def checkTraitInheritance(parent: Symbol, cls: ClassSymbol, pos: SourcePosition)(implicit ctx: Context): Unit = parent match { - case parent: ClassSymbol if parent is Trait => + case parent: ClassSymbol if parent.is(Trait) => val psuper = parent.superClass val csuper = cls.superClass val ok = csuper.derivesFrom(psuper) || @@ -977,7 +977,7 @@ trait Checking { def checkCaseInheritance(parent: Symbol, caseCls: ClassSymbol, pos: SourcePosition)(implicit ctx: Context): Unit = parent match { case parent: ClassSymbol => - if (parent is Case) + if (parent.is(Case)) ctx.error(ex"""case $caseCls has case ancestor $parent, but case-to-case inheritance is prohibited. |To overcome this limitation, use extractors to pattern match on non-leaf nodes.""", pos) else checkCaseInheritance(parent.superClass, caseCls, pos) diff --git a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala index 2474582ac199..e415e183b058 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala @@ -113,7 +113,7 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree], myImpliedBound } - private def implicitFlag(implicit ctx: Context) = + private def implicitFlags(implicit ctx: Context) = if (importImplied || ctx.mode.is(Mode.FindHiddenImplicits)) ImplicitOrImpliedOrGiven else Implicit @@ -121,7 +121,7 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree], def importedImplicits(implicit ctx: Context): List[ImplicitRef] = { val pre = site if (isWildcardImport) - pre.implicitMembers(implicitFlag).flatMap { ref => + pre.implicitMembers(implicitFlags).flatMap { ref => val name = ref.name.toTermName if (excluded.contains(name)) Nil else { @@ -136,7 +136,7 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree], else for { renamed <- reverseMapping.keys - denot <- pre.member(reverseMapping(renamed)).altsWith(_ is implicitFlag) + denot <- pre.member(reverseMapping(renamed)).altsWith(_.isOneOf(implicitFlags)) } yield { val original = reverseMapping(renamed) val ref = TermRef(pre, original, denot) diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 02d915c16854..724e557a2369 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -1149,7 +1149,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { case Some(x) => x > 1 || x == 1 && !boundSym.is(Method) case none => true } - } && !(boundSym.isAll(InlineMethod) && boundSym.is(ImplicitOrImplied)) + } && !(boundSym.isAll(InlineMethod) && boundSym.isOneOf(ImplicitOrImplied)) val inlineBindings = new TreeMap { override def transform(t: Tree)(implicit ctx: Context) = t match { diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 36321e51f8a4..aa549a98ba5f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -112,7 +112,7 @@ trait NamerContextOps { this: Context => } def packageContext(tree: untpd.PackageDef, pkg: Symbol): Context = - if (pkg is Package) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree) + if (pkg.is(Package)) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree) else ctx /** The given type, unless `sym` is a constructor, in which case the @@ -125,7 +125,7 @@ trait NamerContextOps { this: Context => /** if isConstructor, make sure it has one non-implicit parameter list */ def normalizeIfConstructor(termParamss: List[List[Symbol]], isConstructor: Boolean): List[List[Symbol]] = if (isConstructor && - (termParamss.isEmpty || termParamss.head.nonEmpty && (termParamss.head.head is ImplicitOrGiven))) + (termParamss.isEmpty || termParamss.head.nonEmpty && termParamss.head.head.isOneOf(ImplicitOrGiven))) Nil :: termParamss else termParamss @@ -163,7 +163,7 @@ trait NamerContextOps { this: Context => object NamerContextOps { /** Find moduleClass/sourceModule in effective scope */ private def findModuleBuddy(name: Name, scope: Scope)(implicit ctx: Context) = { - val it = scope.lookupAll(name).filter(_ is Module) + val it = scope.lookupAll(name).filter(_.is(Module)) if (it.hasNext) it.next() else NoSymbol.assertingErrorsReported(s"no companion $name in $scope") } @@ -290,7 +290,7 @@ class Namer { typer: Typer => /** Add moduleClass/sourceModule to completer if it is for a module val or class */ def adjustIfModule(completer: LazyType, tree: MemberDef) = - if (tree.mods is Module) ctx.adjustModuleCompleter(completer, tree.name) + if (tree.mods.is(Module)) ctx.adjustModuleCompleter(completer, tree.name) else completer typr.println(i"creating symbol for $tree in ${ctx.mode}") @@ -301,7 +301,7 @@ class Namer { typer: Typer => name.freshened } def preExisting = ctx.effectiveScope.lookup(name) - if (ctx.owner is PackageClass) + if (ctx.owner.is(PackageClass)) if (preExisting.isDefinedInCurrentRun) errorName(s"${preExisting.showLocated} has already been compiled once during this run") else name @@ -370,7 +370,7 @@ class Namer { typer: Typer => // Don't do this for Java constructors because they need to see the import // of the companion object, and it is not necessary for them because they // have no implementation. - val cctx = if (tree.name == nme.CONSTRUCTOR && !(tree.mods is JavaDefined)) ctx.outer else ctx + val cctx = if (tree.name == nme.CONSTRUCTOR && !tree.mods.is(JavaDefined)) ctx.outer else ctx val completer = tree match { case tree: TypeDef => @@ -409,7 +409,7 @@ class Namer { typer: Typer => } val existing = pkgOwner.info.decls.lookup(pid.name) - if ((existing is Package) && (pkgOwner eq existing.owner)) { + if (existing.is(Package) && (pkgOwner eq existing.owner)) { existing.moduleClass.denot match { case d: PackageClassDenotation => // Remove existing members coming from a previous compilation of this file, @@ -459,7 +459,7 @@ class Namer { typer: Typer => def invalidate(name: TypeName) = if (!(definedNames contains name)) { val member = pkg.info.decl(name).asSymDenotation - if (member.isClass && !(member is Package)) member.info = NoType + if (member.isClass && !member.is(Package)) member.info = NoType } xstats foreach { case stat: TypeDef if stat.isClassDef => @@ -532,7 +532,7 @@ class Namer { typer: Typer => def addEnumConstants(mdef: DefTree, sym: Symbol)(implicit ctx: Context): Unit = mdef match { case vdef: ValDef if (isEnumConstant(vdef)) => val enumClass = sym.owner.linkedClass - if (!(enumClass is Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed.toFlags) + if (!enumClass.is(Sealed)) enumClass.setFlag(Flags.AbstractSealed.toFlags) addChild(enumClass, sym) case _ => } @@ -752,7 +752,7 @@ class Namer { typer: Typer => protected def typeSig(sym: Symbol): Type = original match { case original: ValDef => - if (sym is Module) moduleValSig(sym) + if (sym.is(Module)) moduleValSig(sym) else valOrDefDefSig(original, sym, Nil, Nil, identity)(localContext(sym).setNewScope) case original: DefDef => val typer1 = ctx.typer.newLikeThis @@ -917,8 +917,8 @@ class Namer { typer: Typer => val TypeDef(name, impl @ Template(constr, _, self, _)) = original private val (params, rest): (List[Tree], List[Tree]) = impl.body.span { - case td: TypeDef => td.mods is Param - case vd: ValDef => vd.mods is ParamAccessor + case td: TypeDef => td.mods.is(Param) + case vd: ValDef => vd.mods.is(ParamAccessor) case _ => false } @@ -940,7 +940,7 @@ class Namer { typer: Typer => def whyNoForwarder(mbr: SingleDenotation): String = { val sym = mbr.symbol - if (sym.is(ImplicitOrImpliedOrGiven) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}a delegate" + if (sym.isOneOf(ImplicitOrImpliedOrGiven) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}a delegate" else if (!sym.isAccessibleFrom(path.tpe)) "is not accessible" else if (sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge)) SKIP else if (cls.derivesFrom(sym.owner) && @@ -1059,7 +1059,7 @@ class Namer { typer: Typer => val ptype = typedAheadType(tpt).tpe appliedTo targs1.tpes if (ptype.typeParams.isEmpty) ptype else { - if (denot.is(ModuleClass) && denot.sourceModule.is(ImplicitOrImplied)) + if (denot.is(ModuleClass) && denot.sourceModule.isOneOf(ImplicitOrImplied)) missingType(denot.symbol, "parent ")(creationContext) fullyDefinedType(typedAheadExpr(parent).tpe, "class parent", parent.span) } @@ -1195,7 +1195,7 @@ class Namer { typer: Typer => */ def moduleValSig(sym: Symbol)(implicit ctx: Context): Type = { val clsName = sym.name.moduleClassName - val cls = ctx.denotNamed(clsName).suchThat(_ is ModuleClass) + val cls = ctx.denotNamed(clsName).suchThat(_.is(ModuleClass)) .orElse(ctx.newStubSymbol(ctx.owner, clsName).assertingErrorsReported) ctx.owner.thisType.select(clsName, cls) } @@ -1256,7 +1256,7 @@ class Namer { typer: Typer => def rhsProto = sym.asTerm.name collect { case DefaultGetterName(original, idx) => val meth: Denotation = - if (original.isConstructorName && (sym.owner is ModuleClass)) + if (original.isConstructorName && (sym.owner.is(ModuleClass))) sym.owner.companionClass.info.decl(nme.CONSTRUCTOR) else ctx.defContext(sym).denotNamed(original) @@ -1276,7 +1276,7 @@ class Namer { typer: Typer => // println(s"final inherited for $sym: ${inherited.toString}") !!! // println(s"owner = ${sym.owner}, decls = ${sym.owner.info.decls.show}") - def isInlineVal = sym.is(FinalOrInline, butNot = Method | Mutable) + def isInlineVal = sym.isOneOf(FinalOrInline, butNot = Method | Mutable) // Widen rhs type and eliminate `|' but keep ConstantTypes if // definition is inline (i.e. final in Scala2) and keep module singleton types @@ -1330,7 +1330,7 @@ class Namer { typer: Typer => else inherited } else { - if (sym is Implicit) + if (sym.is(Implicit)) mdef match { case _: DefDef => missingType(sym, "result ") case _: ValDef if sym.owner.isType => missingType(sym, "") @@ -1406,7 +1406,7 @@ class Namer { typer: Typer => val termParamss = ctx.normalizeIfConstructor(vparamss.nestedMap(symbolOfTree), isConstructor) def wrapMethType(restpe: Type): Type = { instantiateDependent(restpe, typeParams, termParamss) - ctx.methodType(tparams map symbolOfTree, termParamss, restpe, isJava = ddef.mods is JavaDefined) + ctx.methodType(tparams map symbolOfTree, termParamss, restpe, isJava = ddef.mods.is(JavaDefined)) } if (isConstructor) { // set result type tree to unit, but take the current class as result type of the symbol diff --git a/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala b/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala index ed7cfc0fb618..3ceca092d102 100644 --- a/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala +++ b/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala @@ -50,7 +50,7 @@ object PrepareInlineable { */ def needsAccessor(sym: Symbol)(implicit ctx: Context): Boolean = sym.isTerm && - (sym.is(AccessFlags) || sym.privateWithin.exists) && + (sym.isOneOf(AccessFlags) || sym.privateWithin.exists) && !sym.isContainedIn(inlineSym) && !(sym.isStableMember && sym.info.widenTermRefExpr.isInstanceOf[ConstantType]) && !sym.isInlineMethod diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index dc26d3351b27..8fa375e829dd 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -83,7 +83,7 @@ object RefChecks { * (Forwarding tends to hide problems by binding parameter names). */ private def upwardsThisType(cls: Symbol)(implicit ctx: Context) = cls.info match { - case ClassInfo(_, _, _, _, tp: Type) if (tp ne cls.typeRef) && !cls.is(ModuleOrFinal) => + case ClassInfo(_, _, _, _, tp: Type) if (tp ne cls.typeRef) && !cls.isOneOf(ModuleOrFinal) => SkolemType(cls.appliedRef).withName(nme.this_) case _ => cls.thisType @@ -385,7 +385,7 @@ object RefChecks { "(this rule is designed to prevent ``accidental overrides'')") } else if (other.isStableMember && !member.isStableMember) { // (1.4) overrideError("needs to be a stable, immutable value") - } else if (member.is(ModuleVal) && !other.isRealMethod && !other.is(Deferred | Lazy)) { + } else if (member.is(ModuleVal) && !other.isRealMethod && !other.isOneOf(Deferred | Lazy)) { overrideError("may not override a concrete non-lazy value") } else if (member.is(Lazy, butNot = Module) && !other.isRealMethod && !other.is(Lazy) && !ctx.testScala2Mode(overrideErrorMsg("may not override a non-lazy value"), member.sourcePos)) { @@ -394,7 +394,7 @@ object RefChecks { overrideError("must be declared lazy to override a lazy value") } else if (member.is(Erased) && !other.is(Erased)) { // (1.9.1) overrideError("is erased, cannot override non-erased member") - } else if (other.is(Erased) && !member.is(Erased | Inline)) { // (1.9.1) + } else if (other.is(Erased) && !member.isOneOf(Erased | Inline)) { // (1.9.1) overrideError("is not erased, cannot override erased member") } else if (member.is(Extension) && !other.is(Extension)) { // (1.9.2) overrideError("is an extension method, cannot override a normal method") @@ -447,7 +447,7 @@ object RefChecks { printMixinOverrideErrors() // Verifying a concrete class has nothing unimplemented. - if (!clazz.is(AbstractOrTrait)) { + if (!clazz.isOneOf(AbstractOrTrait)) { val abstractErrors = new mutable.ListBuffer[String] def abstractErrorMessage = // a little formatting polish @@ -638,12 +638,12 @@ object RefChecks { if (!seenClasses.contains(cls)) { seenClasses.addEntry(cls) for (mbr <- cls.info.decls) - if (mbr.isTerm && !mbr.is(Synthetic | Bridge) && mbr.memberCanMatchInheritedSymbols && + if (mbr.isTerm && !mbr.isOneOf(Synthetic | Bridge) && mbr.memberCanMatchInheritedSymbols && !membersToCheck.contains(mbr.name)) membersToCheck.addEntry(mbr.name) cls.info.parents.map(_.classSymbol) - .filter(_.is(AbstractOrTrait)) - .dropWhile(_.is(JavaDefined | Scala2x)) + .filter(_.isOneOf(AbstractOrTrait)) + .dropWhile(_.isOneOf(JavaDefined | Scala2x)) .foreach(addDecls) } addDecls(clazz) diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index b0f3242f83f2..e17c56b81b65 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -30,7 +30,7 @@ trait TypeAssigner { sym.name == qual || sym.is(Module) && sym.name.stripModuleClassSuffix == qual) ctx.outersIterator.map(_.owner).find(qualifies) match { - case Some(c) if packageOK || !(c is Package) => + case Some(c) if packageOK || !c.is(Package) => c case _ => ctx.error( @@ -156,7 +156,7 @@ trait TypeAssigner { avoid(expr.tpe, localSyms(bindings).filter(_.isTerm)) def avoidPrivateLeaks(sym: Symbol, pos: SourcePosition)(implicit ctx: Context): Type = - if (!sym.is(SyntheticOrPrivate) && sym.owner.isClass) checkNoPrivateLeaks(sym, pos) + if (!sym.isOneOf(SyntheticOrPrivate) && sym.owner.isClass) checkNoPrivateLeaks(sym, pos) else sym.info private def toRepeated(tree: Tree, from: ClassSymbol)(implicit ctx: Context): Tree = @@ -550,7 +550,7 @@ trait TypeAssigner { def assignType(tree: untpd.RefinedTypeTree, parent: Tree, refinements: List[Tree], refineCls: ClassSymbol)(implicit ctx: Context): RefinedTypeTree = { def addRefinement(parent: Type, refinement: Tree): Type = { val rsym = refinement.symbol - val rinfo = if (rsym is Accessor) rsym.info.resultType else rsym.info + val rinfo = if (rsym.is(Accessor)) rsym.info.resultType else rsym.info if (rinfo.isError) rinfo else if (!rinfo.exists) parent // can happen after failure in self type definition else RefinedType(parent, rsym.name, rinfo) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 2b9dcc6741c4..9fe0a0fa1dbb 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -139,7 +139,7 @@ class Typer extends Namer reallyExists(denot) && !(pt.isInstanceOf[UnapplySelectionProto] && (denot.symbol is (Method, butNot = Accessor))) && - !(denot.symbol is PackageClass) + !(denot.symbol.is(PackageClass)) /** Find the denotation of enclosing `name` in given context `ctx`. * @param previous A denotation that was found in a more deeply nested scope, @@ -247,7 +247,7 @@ class Typer extends Namer /** Is `denot` the denotation of a self symbol? */ def isSelfDenot(denot: Denotation)(implicit ctx: Context) = denot match { - case denot: SymDenotation => denot is SelfName + case denot: SymDenotation => denot.is(SelfName) case _ => false } @@ -312,12 +312,12 @@ class Typer extends Namer curOwner effectiveOwner.thisType.select(name, defDenot) } - if (!(curOwner is Package) || isDefinedInCurrentUnit(defDenot)) + if (!(curOwner.is(Package)) || isDefinedInCurrentUnit(defDenot)) result = checkNewOrShadowed(found, definition) // no need to go further out, we found highest prec entry else { if (ctx.scala2Mode && !foundUnderScala2.exists) foundUnderScala2 = checkNewOrShadowed(found, definition, scala2pkg = true) - if (defDenot.symbol is Package) + if (defDenot.symbol.is(Package)) result = checkNewOrShadowed(previous orElse found, packageClause) else if (prevPrec < packageClause) result = findRefRecur(found, packageClause, ctx)(ctx.outer) @@ -999,7 +999,7 @@ class Typer extends Namer if !defn.isFunctionType(pt) && mt <:< sam => if (!isFullyDefined(pt, ForceDegree.all)) ctx.error(ex"result type of lambda is an underspecified SAM type $pt", tree.sourcePos) - else if (pt.classSymbol.is(FinalOrSealed)) { + else if (pt.classSymbol.isOneOf(FinalOrSealed)) { val offendingFlag = pt.classSymbol.flags & FinalOrSealed ctx.error(ex"lambda cannot implement $offendingFlag ${pt.classSymbol}", tree.sourcePos) } @@ -1476,7 +1476,7 @@ class Typer extends Namer def typedValDef(vdef: untpd.ValDef, sym: Symbol)(implicit ctx: Context): Tree = track("typedValDef") { val ValDef(name, tpt, _) = vdef completeAnnotations(vdef, sym) - if (sym is ImplicitOrImplied) checkImplicitConversionDefOK(sym) + if (sym.isOneOf(ImplicitOrImplied)) checkImplicitConversionDefOK(sym) val tpt1 = checkSimpleKinded(typedType(tpt)) val rhs1 = vdef.rhs match { case rhs @ Ident(nme.WILDCARD) => rhs withType tpt1.tpe @@ -1521,7 +1521,7 @@ class Typer extends Namer val tparams1 = tparams mapconserve (typed(_).asInstanceOf[TypeDef]) val vparamss1 = vparamss nestedMapconserve (typed(_).asInstanceOf[ValDef]) vparamss1.foreach(checkNoForwardDependencies) - if (sym is ImplicitOrImplied) checkImplicitConversionDefOK(sym) + if (sym.isOneOf(ImplicitOrImplied)) checkImplicitConversionDefOK(sym) val tpt1 = checkSimpleKinded(typedType(tpt)) val rhsCtx = ctx.fresh @@ -1680,7 +1680,7 @@ class Typer extends Namer checkNoDoubleDeclaration(cls) val impl1 = cpy.Template(impl)(constr1, parents1, Nil, self1, body1) .withType(dummy.termRef) - if (!cls.is(AbstractOrTrait) && !ctx.isAfterTyper) + if (!cls.isOneOf(AbstractOrTrait) && !ctx.isAfterTyper) checkRealizableBounds(cls, cdef.sourcePos.withSpan(cdef.nameSpan)) if (cls.derivesFrom(defn.EnumClass)) { val firstParent = parents1.head.tpe.dealias.typeSymbol @@ -1740,7 +1740,7 @@ class Typer extends Namer def ensureFirstIsClass(parents: List[Type], span: Span)(implicit ctx: Context): List[Type] = { def realClassParent(cls: Symbol): ClassSymbol = if (!cls.isClass) defn.ObjectClass - else if (!(cls is Trait)) cls.asClass + else if (!cls.is(Trait)) cls.asClass else cls.asClass.classParents match { case parentRef :: _ => realClassParent(parentRef.typeSymbol) case nil => defn.ObjectClass @@ -1770,7 +1770,7 @@ class Typer extends Namer */ def ensureConstrCall(cls: ClassSymbol, parents: List[Tree])(implicit ctx: Context): List[Tree] = { val firstParent :: otherParents = parents - if (firstParent.isType && !(cls is Trait) && !cls.is(JavaDefined)) + if (firstParent.isType && !cls.is(Trait) && !cls.is(JavaDefined)) typed(untpd.New(untpd.TypedSplice(firstParent), Nil)) :: otherParents else parents } diff --git a/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala b/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala index 8adc740c70f0..763b6030dca3 100644 --- a/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala +++ b/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala @@ -96,7 +96,7 @@ class VarianceChecker()(implicit ctx: Context) { */ def relativeVariance(tvar: Symbol, base: Symbol, v: Variance = Covariant): Variance = /*trace(i"relative variance of $tvar wrt $base, so far: $v")*/ { if (base == tvar.owner) v - else if ((base is Param) && base.owner.isTerm) + else if (base.is(Param) && base.owner.isTerm) relativeVariance(tvar, paramOuter(base.owner), flip(v)) else if (ignoreVarianceIn(base.owner)) Bivariant else if (base.isAliasType) relativeVariance(tvar, base.owner, Invariant) @@ -127,7 +127,7 @@ class VarianceChecker()(implicit ctx: Context) { ctx.log(s"relative variance: ${varianceString(relative)}") ctx.log(s"current variance: ${this.variance}") ctx.log(s"owner chain: ${base.ownersIterator.toList}") - if (tvar is required) None + if (tvar.isOneOf(required)) None else Some(VarianceError(tvar, required)) } } diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index d29c3ae90582..5c7a95aba801 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -261,7 +261,7 @@ class ReplDriver(settings: Array[String], val vals = info.fields - .filterNot(_.symbol.is(ParamAccessor | Private | Synthetic | Module)) + .filterNot(_.symbol.isOneOf(ParamAccessor | Private | Synthetic | Module)) .filter(_.symbol.name.is(SimpleNameKind)) .sortBy(_.name) diff --git a/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala b/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala index 8c2fade43898..dec35d6c44c2 100644 --- a/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala +++ b/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala @@ -61,7 +61,7 @@ class DocASTPhase extends Phase { }.toList // don't add privates, synthetics or class parameters (i.e. value class constructor val) - val vals = sym.info.fields.filterNot(_.symbol.is(Flags.ParamAccessor | Flags.Private | Flags.Synthetic)).map { value => + val vals = sym.info.fields.filterNot(_.symbol.isOneOf(Flags.ParamAccessor | Flags.Private | Flags.Synthetic)).map { value => val kind = if (value.symbol.is(Flags.Mutable)) "var" else "val" ValImpl( value.symbol, @@ -89,7 +89,7 @@ class DocASTPhase extends Phase { /** type alias */ case t: TypeDef if !t.isClassDef => val sym = t.symbol - if (sym.is(Flags.Synthetic | Flags.Param)) + if (sym.isOneOf(Flags.Synthetic | Flags.Param)) Nil else { val tparams = t.rhs.tpe match { diff --git a/doc-tool/src/dotty/tools/dottydoc/core/DocImplicitsPhase.scala b/doc-tool/src/dotty/tools/dottydoc/core/DocImplicitsPhase.scala index fd78422fadb8..6879a4e74e13 100644 --- a/doc-tool/src/dotty/tools/dottydoc/core/DocImplicitsPhase.scala +++ b/doc-tool/src/dotty/tools/dottydoc/core/DocImplicitsPhase.scala @@ -14,7 +14,7 @@ class DocImplicitsPhase extends MiniPhase { override def transformDefDef(tree: DefDef)(implicit ctx: Context): Tree = { if ( - tree.symbol.is(Flags.ImplicitOrImplied) && // has to have an implicit flag + tree.symbol.isOneOf(Flags.ImplicitOrImplied) && // has to have an implicit flag tree.symbol.owner.isStaticOwner && // owner has to be static (e.g. top-level `object`) tree.vparamss.length > 0 && tree.vparamss(0).length == 1 // should only take one arg, since it has to be a transformation From d2abd9001130c3af1eb26afeee697d8faea2d72f Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Wed, 29 May 2019 11:17:12 +0200 Subject: [PATCH 04/25] Remove extra parentheses --- .../src/dotty/tools/backend/jvm/DottyBackendInterface.scala | 2 +- compiler/src/dotty/tools/dotc/ast/tpd.scala | 2 +- compiler/src/dotty/tools/dotc/core/Denotations.scala | 4 ++-- compiler/src/dotty/tools/dotc/core/SymDenotations.scala | 2 +- compiler/src/dotty/tools/dotc/core/Symbols.scala | 2 +- compiler/src/dotty/tools/dotc/core/TypeErasure.scala | 2 +- compiler/src/dotty/tools/dotc/core/Types.scala | 4 ++-- compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala | 2 +- compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala | 2 +- .../src/dotty/tools/dotc/transform/TransformByNameApply.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Applications.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index 2f92e738f838..66f56957421a 100644 --- a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -683,7 +683,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma def isFinal: Boolean = sym.is(Flags.Final) def isStaticMember: Boolean = (sym ne NoSymbol) && - ((sym.is(Flags.JavaStatic)) || toDenot(sym).hasAnnotation(ctx.definitions.ScalaStaticAnnot)) + (sym.is(Flags.JavaStatic) || toDenot(sym).hasAnnotation(ctx.definitions.ScalaStaticAnnot)) // guard against no sumbol cause this code is executed to select which call type(static\dynamic) to use to call array.clone def isBottomClass: Boolean = (sym ne defn.NullClass) && (sym ne defn.NothingClass) diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 001e532027c5..5ce03c7bbe1b 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -289,7 +289,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { if (cls.classInfo.selfInfo ne NoType) ValDef(ctx.newSelfSym(cls)) else EmptyValDef def isOwnTypeParam(stat: Tree) = - (stat.symbol.is(TypeParam)) && stat.symbol.owner == cls + stat.symbol.is(TypeParam) && stat.symbol.owner == cls val bodyTypeParams = body filter isOwnTypeParam map (_.symbol) val newTypeParams = for (tparam <- cls.typeParams if !(bodyTypeParams contains tparam)) diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 87b0a3d08765..5b407a4e3ee1 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -313,7 +313,7 @@ object Denotations { def requiredMethod(pname: PreName, argTypes: List[Type])(implicit ctx: Context): TermSymbol = { val name = pname.toTermName info.member(name).requiredSymbol(i"method", name, this, argTypes) { x => - (x.is(Method)) && { + x.is(Method) && { x.info.paramInfoss match { case paramInfos :: Nil => paramInfos.corresponds(argTypes)(_ =:= _) case _ => false @@ -1370,7 +1370,7 @@ object Denotations { * enter it. */ def missingHook(owner: Symbol, name: Name)(implicit ctx: Context): Symbol = - if ((owner.is(Package)) && name.isTermName) + if (owner.is(Package) && name.isTermName) ctx.newCompletePackageSymbol(owner, name.asTermName).entered else NoSymbol diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index fd69854d76e2..2e82d9d2381a 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1496,7 +1496,7 @@ object SymDenotations { */ private def typeParamsFromDecls(implicit ctx: Context) = unforcedDecls.filter(sym => - (sym.is(TypeParam)) && sym.owner == symbol).asInstanceOf[List[TypeSymbol]] + sym.is(TypeParam) && sym.owner == symbol).asInstanceOf[List[TypeSymbol]] /** The type parameters of this class */ override final def typeParams(implicit ctx: Context): List[TypeSymbol] = { diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index 4c0a56802944..cefb511a991b 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -760,7 +760,7 @@ object Symbols { /** The source or class file from which this class was generated, null if not applicable. */ override def associatedFile(implicit ctx: Context): AbstractFile = - if (assocFile != null || (this.owner.is(PackageClass)) || this.isEffectiveRoot) assocFile + if (assocFile != null || this.owner.is(PackageClass) || this.isEffectiveRoot) assocFile else super.associatedFile private[this] var mySource: SourceFile = NoSource diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index 4e9d24db470b..6246b4ef1636 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -232,7 +232,7 @@ object TypeErasure { } /** Is `tp` an abstract type or polymorphic type parameter that has `Any`, `AnyVal`, - * or a universal trait as upper bound and that.is(not) Java defined? Arrays of such types are + * or a universal trait as upper bound and that is not Java defined? Arrays of such types are * erased to `Object` instead of `Object[]`. */ def isUnboundedGeneric(tp: Type)(implicit ctx: Context): Boolean = tp.dealias match { diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 199481e48cb9..25d61ca68875 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -4325,7 +4325,7 @@ object Types { case et: ExprType => true case _ => false } - if ((tp.cls.is(Trait)) || zeroParams(tp.cls.primaryConstructor.info)) tp // !!! needs to be adapted once traits have parameters + if (tp.cls.is(Trait) || zeroParams(tp.cls.primaryConstructor.info)) tp // !!! needs to be adapted once traits have parameters else NoType case tp: AppliedType => zeroParamClass(tp.superType) @@ -5121,7 +5121,7 @@ object Types { def apply(pre: Type, name: Name)(implicit ctx: Context): Boolean = name.isTypeName && { val mbr = pre.nonPrivateMember(name) - (mbr.symbol.is(Deferred)) && mbr.info.isInstanceOf[RealTypeBounds] + mbr.symbol.is(Deferred) && mbr.info.isInstanceOf[RealTypeBounds] } } diff --git a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala index 66f8edf750b6..d56a12dcb02c 100644 --- a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala @@ -738,7 +738,7 @@ object JavaParsers { } else { if (in.token == ENUM || definesInterface(in.token)) mods |= Flags.JavaStatic val decls = memberDecl(start, mods, parentToken, parentTParams) - (if ((mods.is(Flags.JavaStatic)) || inInterface && !(decls exists (_.isInstanceOf[DefDef]))) + (if (mods.is(Flags.JavaStatic) || inInterface && !(decls exists (_.isInstanceOf[DefDef]))) statics else members) ++= decls diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index 7c932a976d4e..cfb5a8381fd8 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -84,7 +84,7 @@ class PlainPrinter(_ctx: Context) extends Printer { * to the name of the owner. */ protected def hasMeaninglessName(sym: Symbol): Boolean = ( - (sym.is(Param)) && sym.owner.isSetter // x$1 + sym.is(Param) && sym.owner.isSetter // x$1 || sym.isClassConstructor // this || (sym.name == nme.PACKAGE) // package ) diff --git a/compiler/src/dotty/tools/dotc/transform/TransformByNameApply.scala b/compiler/src/dotty/tools/dotc/transform/TransformByNameApply.scala index 9052d173d795..e1129dd04cde 100644 --- a/compiler/src/dotty/tools/dotc/transform/TransformByNameApply.scala +++ b/compiler/src/dotty/tools/dotc/transform/TransformByNameApply.scala @@ -27,7 +27,7 @@ abstract class TransformByNameApply extends MiniPhase { thisPhase: DenotTransfor /** If denotation had an ExprType before, it now gets a function type */ protected def exprBecomesFunction(symd: SymDenotation)(implicit ctx: Context): Boolean = - (symd.is(Param)) || symd.is(ParamAccessor, butNot = Method) + symd.is(Param) || symd.is(ParamAccessor, butNot = Method) protected def isByNameRef(tree: Tree)(implicit ctx: Context): Boolean = { val origDenot = originalDenotation(tree) diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 258d4e092d8d..59f29f2584a3 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -471,7 +471,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => } } val getterPrefix = - if ((meth.is(Synthetic)) && meth.name == nme.apply) nme.CONSTRUCTOR else meth.name + if (meth.is(Synthetic) && meth.name == nme.apply) nme.CONSTRUCTOR else meth.name def getterName = DefaultGetterName(getterPrefix, n) if (!meth.hasDefaultParams) EmptyTree diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 9fe0a0fa1dbb..5a834a83905f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -312,7 +312,7 @@ class Typer extends Namer curOwner effectiveOwner.thisType.select(name, defDenot) } - if (!(curOwner.is(Package)) || isDefinedInCurrentUnit(defDenot)) + if (!curOwner.is(Package) || isDefinedInCurrentUnit(defDenot)) result = checkNewOrShadowed(found, definition) // no need to go further out, we found highest prec entry else { if (ctx.scala2Mode && !foundUnderScala2.exists) From 0fcf5acb3db5d7dbdbcb87f76dc4a56350fbaeb4 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 30 May 2019 16:03:25 +0200 Subject: [PATCH 05/25] Adapt new JSCodeGen change to new scheme --- compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala index 1ae478c0aa95..ace82a9bbc80 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala @@ -447,7 +447,7 @@ class JSCodeGen()(implicit ctx: Context) { "genClassFields called with a ClassDef other than the current one") // Term members that are neither methods nor modules are fields - classSym.info.decls.filter(f => !f.is(Method | Module) && f.isTerm).map({ f => + classSym.info.decls.filter(f => !f.isOneOf(Method | Module) && f.isTerm).map({ f => implicit val pos = f.span val name = From 8399c9f6d7d50d86c9c3d909f6dd13beed184e8c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 30 May 2019 16:15:50 +0200 Subject: [PATCH 06/25] Fix rebase breakage --- compiler/src/dotty/tools/dotc/core/Flags.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index c36c4e27f621..6a11609cef82 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -611,6 +611,9 @@ object Flags { /** Labeled `private`, or `final` */ final val EffectivelyFinalFlags: FlagSet = Private | Final + /** An enum case */ + final val EnumCase: FlagSet = Enum | Case + /** A private method */ final val PrivateMethod: FlagConjunction = allOf(Private, Method) From 51814b04bb1bd8e2fa6655b027e066851d540401 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 19 Jun 2019 11:46:40 +0200 Subject: [PATCH 07/25] Fix rebase breakage --- compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala | 4 ++-- compiler/src/dotty/tools/dotc/core/Flags.scala | 4 ---- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 2 +- .../src/dotty/tools/dotc/transform/CompleteJavaEnums.scala | 4 ++-- compiler/src/dotty/tools/dotc/transform/LazyVals.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Implicits.scala | 2 +- 6 files changed, 7 insertions(+), 11 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala b/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala index 59dd65fef043..e63cfb79fb82 100644 --- a/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala +++ b/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala @@ -286,7 +286,7 @@ object DesugarEnums { val toStringDef = toStringMethLit(name.toString) val impl1 = cpy.Template(impl)(body = List(ordinalDef, toStringDef) ++ registerCall) .withAttachment(ExtendsSingletonMirror, ()) - val vdef = ValDef(name, TypeTree(), New(impl1)).withMods(mods | EnumValue) + val vdef = ValDef(name, TypeTree(), New(impl1)).withMods(mods | EnumValue.toFlags) flatTree(scaffolding ::: vdef :: Nil).withSpan(span) } } @@ -302,7 +302,7 @@ object DesugarEnums { else { val (tag, scaffolding) = nextOrdinal(CaseKind.Simple) val creator = Apply(Ident(nme.DOLLAR_NEW), List(Literal(Constant(tag)), Literal(Constant(name.toString)))) - val vdef = ValDef(name, enumClassRef, creator).withMods(mods | EnumValue) + val vdef = ValDef(name, enumClassRef, creator).withMods(mods | EnumValue.toFlags) flatTree(scaffolding ::: vdef :: Nil).withSpan(span) } } diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 6a11609cef82..ee2821954888 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -611,9 +611,6 @@ object Flags { /** Labeled `private`, or `final` */ final val EffectivelyFinalFlags: FlagSet = Private | Final - /** An enum case */ - final val EnumCase: FlagSet = Enum | Case - /** A private method */ final val PrivateMethod: FlagConjunction = allOf(Private, Method) @@ -637,7 +634,6 @@ object Flags { /** An enum case */ final val EnumCase: FlagConjunction = allOf(Enum, Case) - final val EnumCaseVal: FlagConjunction = allOf(Enum, CaseVal) /** A term parameter or parameter accessor */ final val TermParamOrAccessor: FlagSet = Param | ParamAccessor diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index b54edbc54ec6..7e75c426e474 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2763,7 +2763,7 @@ object Parsers { /** EnumCase = `case' (id ClassConstr [`extends' ConstrApps] | ids) */ def enumCase(start: Offset, mods: Modifiers): DefTree = { - val mods1 = mods | EnumCase + val mods1 = mods | EnumCase.toFlags in.skipCASE() atSpan(start, nameStart) { diff --git a/compiler/src/dotty/tools/dotc/transform/CompleteJavaEnums.scala b/compiler/src/dotty/tools/dotc/transform/CompleteJavaEnums.scala index 73efa0fffe89..c731eeb04b46 100644 --- a/compiler/src/dotty/tools/dotc/transform/CompleteJavaEnums.scala +++ b/compiler/src/dotty/tools/dotc/transform/CompleteJavaEnums.scala @@ -112,7 +112,7 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase => override def transformValDef(tree: ValDef)(implicit ctx: Context): ValDef = { val sym = tree.symbol - if ((sym.is(EnumValue) || sym.name == nme.DOLLAR_VALUES) && sym.owner.linkedClass.derivesFromJavaEnum) + if ((sym.isAll(EnumValue) || sym.name == nme.DOLLAR_VALUES) && sym.owner.linkedClass.derivesFromJavaEnum) sym.addAnnotation(Annotations.Annotation(defn.ScalaStaticAnnot)) tree } @@ -147,7 +147,7 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase => parents = addEnumConstrArgs(defn.JavaEnumClass, templ.parents, addedSyms.map(ref)), body = params ++ addedDefs ++ rest) } - else if (cls.isAnonymousClass && cls.owner.is(EnumCase) && cls.owner.owner.linkedClass.derivesFromJavaEnum) { + else if (cls.isAnonymousClass && cls.owner.isAll(EnumCase) && cls.owner.owner.linkedClass.derivesFromJavaEnum) { def rhsOf(name: TermName) = templ.body.collect { case mdef: DefDef if mdef.name == name => mdef.rhs diff --git a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala index 59c3b50846ce..0f3945bc048d 100644 --- a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala +++ b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala @@ -74,7 +74,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer { else { val isField = sym.owner.isClass if (isField) { - if (sym.is(SyntheticModule)) + if (sym.isAll(SyntheticModule)) transformSyntheticModule(tree) else if (sym.isThreadUnsafe) { if (sym.is(Module)) { diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 85d045542577..5c15cde2b08c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -902,7 +902,7 @@ trait Implicits { self: Typer => } else if (mirroredType.classSymbol.isGenericProduct) { val cls = mirroredType.classSymbol - val accessors = cls.caseAccessors.filterNot(_.is(PrivateLocal)) + val accessors = cls.caseAccessors.filterNot(_.isAll(PrivateLocal)) val elemLabels = accessors.map(acc => ConstantType(Constant(acc.name.toString))) val (monoType, elemsType) = mirroredType match { case mirroredType: HKTypeLambda => From f3120236bdc9bf5d2fe51a1a5d5ac975d291923e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 19 Jun 2019 13:54:00 +0200 Subject: [PATCH 08/25] Rename isAll -> isAllOf Also rename SymDenotaton.is(_, _) to isAllOf --- .../tools/backend/jvm/DottyBackendInterface.scala | 8 ++++---- compiler/src/dotty/tools/dotc/ast/Desugar.scala | 2 +- compiler/src/dotty/tools/dotc/ast/untpd.scala | 4 ++-- .../src/dotty/tools/dotc/config/JavaPlatform.scala | 2 +- compiler/src/dotty/tools/dotc/core/Denotations.scala | 2 +- compiler/src/dotty/tools/dotc/core/Flags.scala | 4 ++-- .../src/dotty/tools/dotc/core/SymDenotations.scala | 12 ++++++------ compiler/src/dotty/tools/dotc/core/Types.scala | 8 ++++---- .../tools/dotc/core/classfile/ClassfileParser.scala | 2 +- .../dotc/core/unpickleScala2/Scala2Unpickler.scala | 4 ++-- .../dotty/tools/dotc/interactive/Completion.scala | 2 +- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 2 +- .../src/dotty/tools/dotc/printing/PlainPrinter.scala | 2 +- .../dotty/tools/dotc/printing/RefinedPrinter.scala | 4 ++-- compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala | 4 ++-- .../dotty/tools/dotc/tastyreflect/KernelImpl.scala | 2 +- .../tools/dotc/transform/AugmentScala2Traits.scala | 2 +- .../tools/dotc/transform/CollectNullableFields.scala | 2 +- .../tools/dotc/transform/CompleteJavaEnums.scala | 4 ++-- .../dotty/tools/dotc/transform/Constructors.scala | 6 +++--- .../dotty/tools/dotc/transform/ExpandPrivate.scala | 4 ++-- .../src/dotty/tools/dotc/transform/Getters.scala | 2 +- .../src/dotty/tools/dotc/transform/LazyVals.scala | 2 +- .../dotty/tools/dotc/transform/LinkScala2Impls.scala | 2 +- compiler/src/dotty/tools/dotc/transform/Mixin.scala | 4 ++-- .../dotty/tools/dotc/transform/PCPCheckAndHeal.scala | 2 +- .../dotty/tools/dotc/transform/PatternMatcher.scala | 2 +- .../dotty/tools/dotc/transform/SelectStatic.scala | 2 +- .../src/dotty/tools/dotc/transform/Splicer.scala | 2 +- .../dotty/tools/dotc/transform/SuperAccessors.scala | 2 +- .../src/dotty/tools/dotc/transform/TreeChecker.scala | 2 +- .../dotty/tools/dotc/transform/patmat/Space.scala | 8 ++++---- .../src/dotty/tools/dotc/typer/Applications.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Checking.scala | 4 ++-- compiler/src/dotty/tools/dotc/typer/Implicits.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Inliner.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Namer.scala | 2 +- compiler/src/dotty/tools/dotc/typer/RefChecks.scala | 4 ++-- compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- .../src/dotty/tools/dotc/typer/VarianceChecker.scala | 6 +++--- 40 files changed, 68 insertions(+), 68 deletions(-) diff --git a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index 66f56957421a..8f271469d732 100644 --- a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -256,7 +256,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma case t: TypeApply if (t.fun.symbol == Predef_classOf) => av.visit(name, t.args.head.tpe.classSymbol.denot.info.toTypeKind(bcodeStore)(innerClasesStore).toASMType) case t: tpd.RefTree => - if (t.symbol.denot.owner.isAll(Flags.JavaEnum)) { + if (t.symbol.denot.owner.isAllOf(Flags.JavaEnum)) { val edesc = innerClasesStore.typeDescriptor(t.tpe.asInstanceOf[bcodeStore.int.Type]) // the class descriptor of the enumeration class. val evalue = t.symbol.name.mangledString // value the actual enumeration value. av.visitEnum(name, edesc, evalue) @@ -477,7 +477,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma // unrelated change. ctx.base.settings.YnoGenericSig.value || sym.is(Flags.Artifact) - || sym.isAll(Flags.LiftedMethod) + || sym.isAllOf(Flags.LiftedMethod) || sym.is(Flags.Bridge) ) @@ -689,13 +689,13 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma def isBottomClass: Boolean = (sym ne defn.NullClass) && (sym ne defn.NothingClass) def isBridge: Boolean = sym.is(Flags.Bridge) def isArtifact: Boolean = sym.is(Flags.Artifact) - def hasEnumFlag: Boolean = sym.isAll(Flags.JavaEnum) + def hasEnumFlag: Boolean = sym.isAllOf(Flags.JavaEnum) def hasAccessBoundary: Boolean = sym.accessBoundary(defn.RootClass) ne defn.RootClass def isVarargsMethod: Boolean = sym.is(Flags.JavaVarargs) def isDeprecated: Boolean = false def isMutable: Boolean = sym.is(Flags.Mutable) def hasAbstractFlag: Boolean = - (sym.is(Flags.Abstract)) || (sym.isAll(Flags.JavaInterface)) || (sym.is(Flags.Trait)) + (sym.is(Flags.Abstract)) || (sym.isAllOf(Flags.JavaInterface)) || (sym.is(Flags.Trait)) def hasModuleFlag: Boolean = sym.is(Flags.Module) def isSynchronized: Boolean = sym.is(Flags.Synchronized) def isNonBottomSubClass(other: Symbol): Boolean = sym.derivesFrom(other) diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 8e22501699df..5aa6e4c252ea 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -159,7 +159,7 @@ object desugar { val vdef @ ValDef(name, tpt, rhs) = transformQuotedPatternName(vdef0) val mods = vdef.mods val setterNeeded = - mods.is(Mutable) && ctx.owner.isClass && (!mods.isAll(PrivateLocal) || ctx.owner.is(Trait)) + mods.is(Mutable) && ctx.owner.isClass && (!mods.isAllOf(PrivateLocal) || ctx.owner.is(Trait)) if (setterNeeded) { // TODO: copy of vdef as getter needed? // val getter = ValDef(mods, name, tpt, rhs) withPos vdef.pos? diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index 7eb98aafef75..104d26ab3b23 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -187,7 +187,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { def is(fs: FlagSet, butNot: FlagSet): Boolean = flags.is(fs, butNot = butNot) def isOneOf(fs: FlagSet): Boolean = flags.isOneOf(fs) def isOneOf(fs: FlagSet, butNot: FlagSet): Boolean = flags.isOneOf(fs, butNot = butNot) - def isAll(fc: FlagConjunction): Boolean = flags.isAll(fc) + def isAllOf(fc: FlagConjunction): Boolean = flags.isAllOf(fc) def | (fs: FlagSet): Modifiers = withFlags(flags | fs) def & (fs: FlagSet): Modifiers = withFlags(flags & fs) @@ -217,7 +217,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { else { if (ms.nonEmpty) for (m <- ms) - assert(flags.isAll(allOf(m.flags)) || + assert(flags.isAllOf(allOf(m.flags)) || m.isInstanceOf[Mod.Private] && !privateWithin.isEmpty, s"unaccounted modifier: $m in $this when adding $ms") copy(mods = ms) diff --git a/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala b/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala index bd39be3297d9..2005a2add3b2 100644 --- a/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala +++ b/compiler/src/dotty/tools/dotc/config/JavaPlatform.scala @@ -39,7 +39,7 @@ class JavaPlatform extends Platform { /** Is the SAMType `cls` also a SAM under the rules of the JVM? */ def isSam(cls: ClassSymbol)(implicit ctx: Context): Boolean = - cls.isAll(NoInitsTrait) && + cls.isAllOf(NoInitsTrait) && cls.superClass == defn.ObjectClass && cls.directlyInheritedTraits.forall(_.is(NoInits)) && !ExplicitOuter.needsOuterIfReferenced(cls) && diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 5b407a4e3ee1..235dc81febf4 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -1152,7 +1152,7 @@ object Denotations { case symd: SymDenotation => symd case _ => symbol.denot } - symd.isAll(required) && !symd.isOneOf(excluded) + symd.isAllOf(required) && !symd.isOneOf(excluded) } } diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index ee2821954888..63205e6312e2 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -64,7 +64,7 @@ object Flags { /** Does this flag set have all of the flags in given flag conjunction? * Pre: The intersection of the typeflags of both sets must be non-empty. */ - def isAll(flags: FlagConjunction): Boolean = { + def isAllOf(flags: FlagConjunction): Boolean = { val fs = bits & flags.bits ((fs & KINDFLAGS) != 0 || flags.bits == 0) && (fs >>> TYPESHIFT) == (flags.bits >>> TYPESHIFT) @@ -74,7 +74,7 @@ object Flags { * and at the same time contain none of the flags in the `butNot` set? * Pre: The intersection of the typeflags of both sets must be non-empty. */ - def isAll(flags: FlagConjunction, butNot: FlagSet): Boolean = isAll(flags) && !is(butNot) + def isAllOf(flags: FlagConjunction, butNot: FlagSet): Boolean = isAllOf(flags) && !is(butNot) def isEmpty: Boolean = (bits & ~KINDFLAGS) == 0 diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 2e82d9d2381a..166cef8bdb0a 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -207,14 +207,14 @@ object SymDenotations { (if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags).isOneOf(fs, butNot) /** Has this denotation all of the flags in `fs` set? */ - final def isAll(fs: FlagConjunction)(implicit ctx: Context): Boolean = - (if (isCurrent(fs.toFlags)) myFlags else flags).isAll(fs) + final def isAllOf(fs: FlagConjunction)(implicit ctx: Context): Boolean = + (if (isCurrent(fs.toFlags)) 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 is(fs: FlagConjunction, butNot: FlagSet)(implicit ctx: Context): Boolean = - (if (isCurrent(fs.toFlags) && isCurrent(butNot)) myFlags else flags).isAll(fs, butNot) + final def isAllOf(fs: FlagConjunction, butNot: FlagSet)(implicit ctx: Context): Boolean = + (if (isCurrent(fs.toFlags) && 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 @@ -848,7 +848,7 @@ object SymDenotations { def isSkolem: Boolean = name == nme.SKOLEM def isInlineMethod(implicit ctx: Context): Boolean = - is(InlineMethod, butNot = Accessor) && + isAllOf(InlineMethod, butNot = Accessor) && !name.isUnapplyName // unapply methods do not count as inline methods // we need an inline flag on them only do that // reduceProjection gets access to their rhs @@ -1245,7 +1245,7 @@ object SymDenotations { final def accessBoundary(base: Symbol)(implicit ctx: Context): Symbol = { val fs = flags if (fs.is(Private)) owner - else if (fs.isAll(StaticProtected)) defn.RootClass + else if (fs.isAllOf(StaticProtected)) defn.RootClass else if (privateWithin.exists && !ctx.phase.erasedTypes) privateWithin else if (fs.is(Protected)) base else defn.RootClass diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 25d61ca68875..fc8e3e8c1c1e 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -235,7 +235,7 @@ object Types { * from the ThisType of `symd`'s owner. */ def isArgPrefixOf(symd: SymDenotation)(implicit ctx: Context): Boolean = - symd.isAll(ClassTypeParam) && { + symd.isAllOf(ClassTypeParam) && { this match { case tp: ThisType => tp.cls ne symd.owner case _ => true @@ -2149,7 +2149,7 @@ object Types { else { if (isType) { val res = - if (currentSymbol.isAll(ClassTypeParam)) argForParam(prefix) + if (currentSymbol.isAllOf(ClassTypeParam)) argForParam(prefix) else prefix.lookupRefined(name) if (res.exists) return res if (Config.splitProjections) @@ -4375,7 +4375,7 @@ object Types { // (x: String): Int val approxParams = new ApproximatingTypeMap { def apply(tp: Type): Type = tp match { - case tp: TypeRef if tp.symbol.isAll(ClassTypeParam) && tp.symbol.owner == cls => + case tp: TypeRef if tp.symbol.isAllOf(ClassTypeParam) && tp.symbol.owner == cls => tp.info match { case info: AliasingBounds => mapOver(info.alias) @@ -4717,7 +4717,7 @@ object Types { else pre match { case Range(preLo, preHi) => val forwarded = - if (tp.symbol.isAll(ClassTypeParam)) expandParam(tp, preHi) + if (tp.symbol.isAllOf(ClassTypeParam)) expandParam(tp, preHi) else tryWiden(tp, preHi) forwarded.orElse( range(super.derivedSelect(tp, preLo).loBound, super.derivedSelect(tp, preHi).hiBound)) diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 2fb6d7f20e69..177dc7f6c559 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -583,7 +583,7 @@ class ClassfileParser( parseExceptions(attrLen) case tpnme.CodeATTR => - if (sym.owner.isAll(Flags.JavaTrait)) { + if (sym.owner.isAllOf(Flags.JavaTrait)) { sym.resetFlag(Flags.Deferred) sym.owner.resetFlag(Flags.PureInterface) ctx.log(s"$sym in ${sym.owner} is a java8+ default method.") diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 5f36bf25f1b3..aa3027c58394 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -120,7 +120,7 @@ object Scala2Unpickler { if (tsym.exists) tsym.setFlag(TypeParam) else denot.enter(tparam, decls) } - if (!denot.flagsUNSAFE.isAll(JavaModule)) ensureConstructor(denot.symbol.asClass, decls) + if (!denot.flagsUNSAFE.isAllOf(JavaModule)) ensureConstructor(denot.symbol.asClass, decls) val scalacCompanion = denot.classSymbol.scalacLinkedClass @@ -436,7 +436,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas val owner = readSymbolRef() var flags = unpickleScalaFlags(readLongNat(), name.isTypeName) - if (flags.isAll(DefaultParameter)) { + if (flags.isAllOf(DefaultParameter)) { // DefaultParameterized flag now on method, not parameter //assert(flags.is(Param), s"$name0 in $owner") flags = flags &~ DefaultParameterized diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index 684c8c4bf3f8..c1dcc5bb29f6 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -255,7 +255,7 @@ object Completion { !sym.isPrimaryConstructor && sym.sourceSymbol.exists && (!sym.is(Package) || sym.is(ModuleClass)) && - !sym.isAll(allOf(Mutable, Accessor)) && + !sym.isAllOf(allOf(Mutable, Accessor)) && !sym.isPackageObject && !sym.is(Artifact) && ( diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 7e75c426e474..ef6ac80fd743 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2039,7 +2039,7 @@ object Parsers { private def normalize(mods: Modifiers): Modifiers = if (mods.is(Private) && mods.hasPrivateWithin) normalize(mods &~ Private) - else if (mods.isAll(AbstractAndOverride)) + else if (mods.isAllOf(AbstractAndOverride)) normalize(addFlag(mods &~ (Abstract | Override), AbsOverride)) else mods diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index cfb5a8381fd8..d79f99d02260 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -391,7 +391,7 @@ class PlainPrinter(_ctx: Context) extends Printer { /** String representation of symbol's definition keyword */ protected def keyString(sym: Symbol): String = { val flags = sym.flagsUNSAFE - if (flags.isAll(JavaTrait)) "interface" + if (flags.isAllOf(JavaTrait)) "interface" else if (flags.is(Trait)) "trait" else if (flags.is(Module)) "object" else if (sym.isClass) "class" diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index f6aa540916bd..7c5e71a10999 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -816,7 +816,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { protected def annotText(tree: untpd.Tree): Text = "@" ~ constrText(tree) // DD protected def modText(mods: untpd.Modifiers, sym: Symbol, kw: String, isType: Boolean): Text = { // DD - val suppressKw = if (enclDefIsClass) mods.isAll(ParamAndLocal) else mods.is(Param) + val suppressKw = if (enclDefIsClass) mods.isAllOf(ParamAndLocal) else mods.is(Param) var flagMask = if (ctx.settings.YdebugFlags.value) AnyFlags else if (suppressKw) PrintableFlags(isType) &~ Private @@ -847,7 +847,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { override protected def treatAsTypeParam(sym: Symbol): Boolean = sym.is(TypeParam) override protected def treatAsTypeArg(sym: Symbol): Boolean = - sym.isType && (sym.isAll(ProtectedLocal)) && + sym.isType && (sym.isAllOf(ProtectedLocal)) && (sym.allOverriddenSymbols exists (_.is(TypeParam))) override def toText(sym: Symbol): Text = { diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala index 958707f4ee16..39efcb32a33d 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala @@ -567,9 +567,9 @@ private class ExtractAPICollector(implicit val ctx: Context) extends ThunkHolder // but their `privateWithin` exists, see `Parsers#ParserCommon#normalize`. if (!sym.isOneOf(Protected | Private) && !sym.privateWithin.exists) Constants.public - else if (sym.isAll(PrivateLocal)) + else if (sym.isAllOf(PrivateLocal)) Constants.privateLocal - else if (sym.isAll(ProtectedLocal)) + else if (sym.isAllOf(ProtectedLocal)) Constants.protectedLocal else { val qualifier = diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index 10b5985cab59..841866fd03e1 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -1680,7 +1680,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Flags = core.Flags.FlagSet /** Is the given flag set a subset of this flag sets */ - def Flags_is(self: Flags)(that: Flags): Boolean = self.isAll(allOf(that)) + def Flags_is(self: Flags)(that: Flags): Boolean = self.isAllOf(allOf(that)) /** Union of the two flag sets */ def Flags_or(self: Flags)(that: Flags): Flags = self | that diff --git a/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala b/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala index fae404e7ee12..3d5267f8effc 100644 --- a/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala +++ b/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala @@ -59,7 +59,7 @@ class AugmentScala2Traits extends MiniPhase with IdentityDenotTransformer { this if (sym.isGetter && !sym.is(LazyOrDeferred) && !sym.setter.exists && !sym.info.resultType.isInstanceOf[ConstantType]) traitSetter(sym.asTerm).enteredAfter(thisPhase) - if ((sym.isAll(PrivateAccessor) && !sym.name.is(ExpandedName) && + if ((sym.isAllOf(PrivateAccessor) && !sym.name.is(ExpandedName) && (sym.isGetter || sym.isSetter)) // strangely, Scala 2 fields are also methods that have Accessor set. || sym.isSuperAccessor) // scala2 superaccessors are pickled as private, but are compiled as public expanded sym.ensureNotPrivate.installAfter(thisPhase) diff --git a/compiler/src/dotty/tools/dotc/transform/CollectNullableFields.scala b/compiler/src/dotty/tools/dotc/transform/CollectNullableFields.scala index c6fbd64c426d..95e5e551d0d6 100644 --- a/compiler/src/dotty/tools/dotc/transform/CollectNullableFields.scala +++ b/compiler/src/dotty/tools/dotc/transform/CollectNullableFields.scala @@ -64,7 +64,7 @@ class CollectNullableFields extends MiniPhase { sym.isField && !sym.is(Lazy) && !sym.owner.is(Trait) && - sym.initial.isAll(PrivateLocal) && + sym.initial.isAllOf(PrivateLocal) && sym.info.widenDealias.typeSymbol.isNullableClass if (isNullablePrivateField) diff --git a/compiler/src/dotty/tools/dotc/transform/CompleteJavaEnums.scala b/compiler/src/dotty/tools/dotc/transform/CompleteJavaEnums.scala index c731eeb04b46..75f5d453fe5a 100644 --- a/compiler/src/dotty/tools/dotc/transform/CompleteJavaEnums.scala +++ b/compiler/src/dotty/tools/dotc/transform/CompleteJavaEnums.scala @@ -112,7 +112,7 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase => override def transformValDef(tree: ValDef)(implicit ctx: Context): ValDef = { val sym = tree.symbol - if ((sym.isAll(EnumValue) || sym.name == nme.DOLLAR_VALUES) && sym.owner.linkedClass.derivesFromJavaEnum) + if ((sym.isAllOf(EnumValue) || sym.name == nme.DOLLAR_VALUES) && sym.owner.linkedClass.derivesFromJavaEnum) sym.addAnnotation(Annotations.Annotation(defn.ScalaStaticAnnot)) tree } @@ -147,7 +147,7 @@ class CompleteJavaEnums extends MiniPhase with InfoTransformer { thisPhase => parents = addEnumConstrArgs(defn.JavaEnumClass, templ.parents, addedSyms.map(ref)), body = params ++ addedDefs ++ rest) } - else if (cls.isAnonymousClass && cls.owner.isAll(EnumCase) && cls.owner.owner.linkedClass.derivesFromJavaEnum) { + else if (cls.isAnonymousClass && cls.owner.isAllOf(EnumCase) && cls.owner.owner.linkedClass.derivesFromJavaEnum) { def rhsOf(name: TermName) = templ.body.collect { case mdef: DefDef if mdef.name == name => mdef.rhs diff --git a/compiler/src/dotty/tools/dotc/transform/Constructors.scala b/compiler/src/dotty/tools/dotc/transform/Constructors.scala index f8ea24f80d05..3cf141ecd6b0 100644 --- a/compiler/src/dotty/tools/dotc/transform/Constructors.scala +++ b/compiler/src/dotty/tools/dotc/transform/Constructors.scala @@ -99,7 +99,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase = */ override def checkPostCondition(tree: tpd.Tree)(implicit ctx: Context): Unit = { def emptyRhsOK(sym: Symbol) = - sym.isOneOf(LazyOrDeferred) || sym.isConstructor && sym.owner.isAll(NoInitsTrait) + sym.isOneOf(LazyOrDeferred) || sym.isConstructor && sym.owner.isAllOf(NoInitsTrait) tree match { case tree: ValDef if tree.symbol.exists && tree.symbol.owner.isClass && !tree.symbol.is(Lazy) && !tree.symbol.hasAnnotation(defn.ScalaStaticAnnot) => assert(tree.rhs.isEmpty, i"$tree: initializer should be moved to constructors") @@ -119,7 +119,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase = * constructor. */ private def mightBeDropped(sym: Symbol)(implicit ctx: Context) = - sym.is(Private, butNot = MethodOrLazy) && !sym.isAll(MutableParamAccessor) + sym.is(Private, butNot = MethodOrLazy) && !sym.isAllOf(MutableParamAccessor) private final val MutableParamAccessor = allOf(Mutable, ParamAccessor) @@ -275,7 +275,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase = val finalConstrStats = copyParams ::: mappedSuperCalls ::: lazyAssignments ::: stats val expandedConstr = - if (cls.isAll(NoInitsTrait)) { + if (cls.isAllOf(NoInitsTrait)) { assert(finalConstrStats.isEmpty) constr } diff --git a/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala b/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala index 1376253e978c..04f2cf02e90e 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala @@ -58,7 +58,7 @@ class ExpandPrivate extends MiniPhase with IdentityDenotTransformer { thisPhase } private def isVCPrivateParamAccessor(d: SymDenotation)(implicit ctx: Context) = - d.isTerm && d.isAll(PrivateParamAccessor) && isDerivedValueClass(d.owner) + d.isTerm && d.isAllOf(PrivateParamAccessor) && isDerivedValueClass(d.owner) /** Make private terms accessed from different classes non-private. * Note: this happens also for accesses between class and linked module class. @@ -105,7 +105,7 @@ class ExpandPrivate extends MiniPhase with IdentityDenotTransformer { thisPhase val sym = tree.symbol tree.rhs match { case Apply(sel @ Select(_: Super, _), _) - if sym.isAll(PrivateParamAccessor) && sel.symbol.is(ParamAccessor) && sym.name == sel.symbol.name => + if sym.isAllOf(PrivateParamAccessor) && sel.symbol.is(ParamAccessor) && sym.name == sel.symbol.name => sym.ensureNotPrivate.installAfter(thisPhase) case _ => if (isVCPrivateParamAccessor(sym)) diff --git a/compiler/src/dotty/tools/dotc/transform/Getters.scala b/compiler/src/dotty/tools/dotc/transform/Getters.scala index 1e86d9f07f1b..fee742c27af6 100644 --- a/compiler/src/dotty/tools/dotc/transform/Getters.scala +++ b/compiler/src/dotty/tools/dotc/transform/Getters.scala @@ -54,7 +54,7 @@ class Getters extends MiniPhase with SymTransformer { override def transformSym(d: SymDenotation)(implicit ctx: Context): SymDenotation = { def noGetterNeeded = d.isOneOf(NoGetterNeededFlags) || - d.isAll(PrivateLocal) && !d.owner.is(Trait) && !isDerivedValueClass(d.owner) && !d.is(Lazy) || + d.isAllOf(PrivateLocal) && !d.owner.is(Trait) && !isDerivedValueClass(d.owner) && !d.is(Lazy) || d.is(Module) && d.isStatic || d.hasAnnotation(defn.ScalaStaticAnnot) || d.isSelfSym diff --git a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala index 0f3945bc048d..ea3b1e02f3cd 100644 --- a/compiler/src/dotty/tools/dotc/transform/LazyVals.scala +++ b/compiler/src/dotty/tools/dotc/transform/LazyVals.scala @@ -74,7 +74,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer { else { val isField = sym.owner.isClass if (isField) { - if (sym.isAll(SyntheticModule)) + if (sym.isAllOf(SyntheticModule)) transformSyntheticModule(tree) else if (sym.isThreadUnsafe) { if (sym.is(Module)) { diff --git a/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala b/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala index 97c6fad4e0e1..a6a21fe2499f 100644 --- a/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala +++ b/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala @@ -88,7 +88,7 @@ class LinkScala2Impls extends MiniPhase with IdentityDenotTransformer { thisPhas private def implMethod(meth: Symbol)(implicit ctx: Context): Symbol = { val implName = ImplMethName(meth.name.asTermName) val cls = meth.owner - if (cls.isAll(Scala2xTrait)) + if (cls.isAllOf(Scala2xTrait)) if (meth.isConstructor) cls.info.decl(nme.TRAIT_CONSTRUCTOR).symbol else diff --git a/compiler/src/dotty/tools/dotc/transform/Mixin.scala b/compiler/src/dotty/tools/dotc/transform/Mixin.scala index 119bdfa84b90..f4d05919f31e 100644 --- a/compiler/src/dotty/tools/dotc/transform/Mixin.scala +++ b/compiler/src/dotty/tools/dotc/transform/Mixin.scala @@ -196,10 +196,10 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase => def superCallOpt(baseCls: Symbol): List[Tree] = superCalls.get(baseCls) match { case Some(call) => - if (defn.NotRuntimeClasses.contains(baseCls) || baseCls.isAll(NoInitsTrait)) Nil + if (defn.NotRuntimeClasses.contains(baseCls) || baseCls.isAllOf(NoInitsTrait)) Nil else call :: Nil case None => - if (baseCls.isAll(NoInitsTrait) || defn.NoInitClasses.contains(baseCls) || defn.isFunctionClass(baseCls)) Nil + if (baseCls.isAllOf(NoInitsTrait) || defn.NoInitClasses.contains(baseCls) || defn.isFunctionClass(baseCls)) Nil else { //println(i"synth super call ${baseCls.primaryConstructor}: ${baseCls.primaryConstructor.info}") transformFollowingDeep(superRef(baseCls.primaryConstructor).appliedToNone) :: Nil diff --git a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala index 50f9b5540428..1dec5e16b95e 100644 --- a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala +++ b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala @@ -93,7 +93,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages( tree match { case Quoted(_) | Spliced(_) => tree - case tree: RefTree if tree.symbol.isAll(InlineParam) => + case tree: RefTree if tree.symbol.isAllOf(InlineParam) => tree case _: This => assert(checkSymLevel(tree.symbol, tree.tpe, tree.sourcePos).isEmpty) diff --git a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala index 3675d09ce24e..36825c2cd2d6 100644 --- a/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -310,7 +310,7 @@ object PatternMatcher { lazy val caseAccessors = caseClass.caseAccessors.filter(_.is(Method)) def isSyntheticScala2Unapply(sym: Symbol) = - sym.isAll(SyntheticCase) && sym.owner.is(Scala2x) + sym.isAllOf(SyntheticCase) && sym.owner.is(Scala2x) if (isSyntheticScala2Unapply(unapp.symbol) && caseAccessors.length == args.length) matchArgsPlan(caseAccessors.map(ref(scrutinee).select(_)), args, onSuccess) diff --git a/compiler/src/dotty/tools/dotc/transform/SelectStatic.scala b/compiler/src/dotty/tools/dotc/transform/SelectStatic.scala index d3f64ee72946..396023b248fd 100644 --- a/compiler/src/dotty/tools/dotc/transform/SelectStatic.scala +++ b/compiler/src/dotty/tools/dotc/transform/SelectStatic.scala @@ -28,7 +28,7 @@ class SelectStatic extends MiniPhase with IdentityDenotTransformer { sym.hasAnnotation(ctx.definitions.ScalaStaticAnnot) val isStaticRef = !sym.is(Package) && !sym.maybeOwner.is(Package) && isStaticMember val tree1 = - if (isStaticRef && !tree.qualifier.symbol.isAll(JavaModule) && !tree.qualifier.isType) + if (isStaticRef && !tree.qualifier.symbol.isAllOf(JavaModule) && !tree.qualifier.isType) Block(List(tree.qualifier), ref(sym)) else tree diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index df2ff38e42d5..291054059ddf 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -316,7 +316,7 @@ object Splicer { protected final def interpretTree(tree: Tree)(implicit env: Env): Result = tree match { case Apply(TypeApply(fn, _), quoted :: Nil) if fn.symbol == defn.InternalQuoted_exprQuote => val quoted1 = quoted match { - case quoted: Ident if quoted.symbol.isAll(InlineByNameProxy) => + case quoted: Ident if quoted.symbol.isAllOf(InlineByNameProxy) => // inline proxy for by-name parameter quoted.symbol.defTree.asInstanceOf[DefDef].rhs case Inlined(EmptyTree, _, quoted) => quoted diff --git a/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala b/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala index 90aad9550375..ff2de86f5cc6 100644 --- a/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala +++ b/compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala @@ -100,7 +100,7 @@ class SuperAccessors(thisPhase: DenotTransformer) { assert(sup.symbol.exists, s"missing symbol in $sel: ${sup.tpe}") val clazz = sup.symbol - if (sym.isTerm && !sym.is(Method, butNot = Accessor) && !ctx.owner.isAll(ParamForwarder)) + if (sym.isTerm && !sym.is(Method, butNot = Accessor) && !ctx.owner.isAllOf(ParamForwarder)) // ParamForwaders as installed ParamForwarding.scala do use super calls to vals ctx.error(s"super may be not be used on ${sym.underlyingSymbol}", sel.sourcePos) else if (isDisallowed(sym)) diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index 843544996acb..4f61563d4e31 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -185,7 +185,7 @@ class TreeChecker extends Phase with SymTransformer { /** assert Java classes are not used as objects */ def assertIdentNotJavaClass(tree: Tree)(implicit ctx: Context): Unit = tree match { case _ : untpd.Ident => - assert(!tree.symbol.isAll(JavaModule), "Java class can't be used as value: " + tree) + assert(!tree.symbol.isAllOf(JavaModule), "Java class can't be used as value: " + tree) case _ => } diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 30f98ab8a668..9a721bbee4d4 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -424,7 +424,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { lazy val caseAccessors = caseClass.caseAccessors.filter(_.is(Method)) def isSyntheticScala2Unapply(sym: Symbol) = - sym.isAll(SyntheticCase) && sym.owner.is(Scala2x) + sym.isAllOf(SyntheticCase) && sym.owner.is(Scala2x) val mt @ MethodType(_) = unapp.widen @@ -494,7 +494,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { ) case tp if tp.isRef(defn.UnitClass) => Typ(ConstantType(Constant(())), true) :: Nil - case tp if tp.classSymbol.isAll(JavaEnum) => + case tp if tp.classSymbol.isAllOf(JavaEnum) => children.map(sym => Typ(sym.termRef, true)) case tp => val parts = children.map { sym => @@ -535,7 +535,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { }) || tp.isRef(defn.BooleanClass) || tp.isRef(defn.UnitClass) || - tp.classSymbol.isAll(JavaEnumTrait) + tp.classSymbol.isAllOf(JavaEnumTrait) debug.println(s"decomposable: ${tp.show} = $res") @@ -681,7 +681,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { isCheckable(and.tp1) || isCheckable(and.tp2) }) || tpw.isRef(defn.BooleanClass) || - tpw.typeSymbol.isAll(JavaEnum) || + tpw.typeSymbol.isAllOf(JavaEnum) || (defn.isTupleType(tpw) && tpw.argInfos.exists(isCheckable(_))) } diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 59f29f2584a3..a99d4f6a0c9f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -1370,7 +1370,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => case pt: PolyType => pt.derivedLambdaType(pt.paramNames, pt.paramInfos, widenImplied(pt.resultType, alt)) case _ => - if (alt.symbol.isAll(SyntheticImpliedMethod)) tp.widenToParents + if (alt.symbol.isAllOf(SyntheticImpliedMethod)) tp.widenToParents else tp } diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 54bc085489a9..66fb90ce05cb 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -392,7 +392,7 @@ object Checking { if (sym.isOneOf(flag)) fail(AbstractMemberMayNotHaveModifier(sym, flag)) def checkNoConflict(flag1: FlagSet, flag2: FlagSet, msg: => String) = - if (sym.isAll(allOf(flag1, flag2))) fail(msg) + if (sym.isAllOf(allOf(flag1, flag2))) fail(msg) def checkCombination(flag1: FlagSet, flag2: FlagSet) = checkNoConflict(flag1, flag2, i"illegal combination of modifiers: `$flag1` and `$flag2` for: $sym") def checkApplicable(flag: FlagSet, ok: Boolean) = @@ -600,7 +600,7 @@ trait Checking { val sym = tree.tpe.termSymbol // The check is avoided inside Java compilation units because it always fails // on the singleton type Module.type. - if ((sym is Package) || (sym.isAll(JavaModule) && !ctx.compilationUnit.isJava)) ctx.error(JavaSymbolIsNotAValue(sym), tree.sourcePos) + if ((sym is Package) || (sym.isAllOf(JavaModule) && !ctx.compilationUnit.isJava)) ctx.error(JavaSymbolIsNotAValue(sym), tree.sourcePos) } tree } diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 5c15cde2b08c..f5cf81e6cff8 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -902,7 +902,7 @@ trait Implicits { self: Typer => } else if (mirroredType.classSymbol.isGenericProduct) { val cls = mirroredType.classSymbol - val accessors = cls.caseAccessors.filterNot(_.isAll(PrivateLocal)) + val accessors = cls.caseAccessors.filterNot(_.isAllOf(PrivateLocal)) val elemLabels = accessors.map(acc => ConstantType(Constant(acc.name.toString))) val (monoType, elemsType) = mirroredType match { case mirroredType: HKTypeLambda => diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 724e557a2369..5ab7b1fa9a0a 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -1149,7 +1149,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { case Some(x) => x > 1 || x == 1 && !boundSym.is(Method) case none => true } - } && !(boundSym.isAll(InlineMethod) && boundSym.isOneOf(ImplicitOrImplied)) + } && !(boundSym.isAllOf(InlineMethod) && boundSym.isOneOf(ImplicitOrImplied)) val inlineBindings = new TreeMap { override def transform(t: Tree)(implicit ctx: Context) = t match { diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index aa549a98ba5f..7218167b3ce2 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -503,7 +503,7 @@ class Namer { typer: Typer => /** Determines whether this field holds an enum constant. */ def isEnumConstant(vd: ValDef)(implicit ctx: Context): Boolean = - vd.mods.isAll(JavaEnumValue) + vd.mods.isAllOf(JavaEnumValue) /** Add child annotation for `child` to annotations of `cls`. The annotation * is added at the correct insertion point, so that Child annotations appear diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index 8fa375e829dd..fdd419341881 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -335,7 +335,7 @@ object RefChecks { (member.flags & AccessFlags).isEmpty // member is public || // - or - (!other.is(Protected) || member.is(Protected)) && // if o is protected, so is m, and - (ob.isContainedIn(mb) || other.isAll(JavaProtected)) // m relaxes o's access boundary, + (ob.isContainedIn(mb) || other.isAllOf(JavaProtected)) // m relaxes o's access boundary, // or o is Java defined and protected (see #3946) ) if (!isOverrideAccessOK) { @@ -356,7 +356,7 @@ object RefChecks { // Also exclusion for implicit shortcut methods // Also excluded under Scala2 mode are overrides of default methods of Java traits. if (autoOverride(member) || - other.owner.isAll(JavaTrait) && + other.owner.isAllOf(JavaTrait) && ctx.testScala2Mode("`override' modifier required when a Java 8 default method is re-implemented", member.sourcePos)) member.setFlag(Override) else if (member.isType && self.memberInfo(member) =:= self.memberInfo(other)) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 5a834a83905f..accc44111bfb 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2772,7 +2772,7 @@ class Typer extends Namer // - the current tree is a synthetic apply which is not expandable (eta-expasion would simply undo that) if (arity >= 0 && !tree.symbol.isConstructor && - !tree.symbol.isAll(InlineMethod) && + !tree.symbol.isAllOf(InlineMethod) && !ctx.mode.is(Mode.Pattern) && !(isSyntheticApply(tree) && !isExpandableApply)) { if (!defn.isFunctionType(pt)) diff --git a/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala b/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala index 763b6030dca3..aa44f8178b33 100644 --- a/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala +++ b/compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala @@ -87,7 +87,7 @@ class VarianceChecker()(implicit ctx: Context) { def ignoreVarianceIn(base: Symbol): Boolean = ( base.isTerm || base.is(Package) - || base.isAll(PrivateLocal) + || base.isAllOf(PrivateLocal) ) /** The variance of a symbol occurrence of `tvar` seen at the level of the definition of `base`. @@ -175,7 +175,7 @@ class VarianceChecker()(implicit ctx: Context) { case Some(VarianceError(tvar, required)) => def msg = i"${varianceString(tvar.flags)} $tvar occurs in ${varianceString(required)} position in type ${sym.info} of $sym" if (ctx.scala2Mode && - (sym.owner.isConstructor || sym.ownersIterator.exists(_.isAll(ProtectedLocal)))) { + (sym.owner.isConstructor || sym.ownersIterator.exists(_.isAllOf(ProtectedLocal)))) { ctx.migrationWarning( s"According to new variance rules, this is no longer accepted; need to annotate with @uncheckedVariance:\n$msg", pos) @@ -193,7 +193,7 @@ class VarianceChecker()(implicit ctx: Context) { // No variance check for private/protected[this] methods/values. def skip = !sym.exists || - sym.isAll(PrivateLocal) || + sym.isAllOf(PrivateLocal) || sym.name.is(InlineAccessorName) || // TODO: should we exclude all synthetic members? sym.is(TypeParam) && sym.owner.isClass // already taken care of in primary constructor of class try tree match { From 5659ec8868794eac06a7e299c38ab4d6ccb0ed00 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 19 Jun 2019 14:02:39 +0200 Subject: [PATCH 09/25] Make FlagConjunction an alias of FlagSet Drop .toFlags conversion --- compiler/src/dotty/tools/dotc/ast/Desugar.scala | 6 +++--- compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala | 4 ++-- compiler/src/dotty/tools/dotc/ast/Trees.scala | 2 +- compiler/src/dotty/tools/dotc/ast/untpd.scala | 4 ++-- compiler/src/dotty/tools/dotc/core/Definitions.scala | 6 +++--- compiler/src/dotty/tools/dotc/core/Denotations.scala | 2 +- compiler/src/dotty/tools/dotc/core/Flags.scala | 12 ++---------- .../src/dotty/tools/dotc/core/SymDenotations.scala | 4 ++-- compiler/src/dotty/tools/dotc/core/Symbols.scala | 4 ++-- .../tools/dotc/core/classfile/ClassfileParser.scala | 8 ++++---- .../src/dotty/tools/dotc/parsing/JavaParsers.scala | 10 +++++----- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 12 ++++++------ .../dotty/tools/dotc/tastyreflect/KernelImpl.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Inliner.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Namer.scala | 2 +- 15 files changed, 36 insertions(+), 44 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 5aa6e4c252ea..0d18f37c425f 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -182,7 +182,7 @@ object desugar { def makeImplicitParameters(tpts: List[Tree], implicitFlag: FlagSet, forPrimaryConstructor: Boolean = false)(implicit ctx: Context): List[ValDef] = for (tpt <- tpts) yield { - val paramFlags: FlagSet = if (forPrimaryConstructor) PrivateLocalParamAccessor.toFlags else Param + val paramFlags: FlagSet = if (forPrimaryConstructor) PrivateLocalParamAccessor else Param val epname = EvidenceParamName.fresh() ValDef(epname, tpt, EmptyTree).withFlags(paramFlags | implicitFlag) } @@ -403,7 +403,7 @@ object desugar { val tparamReferenced = typeParamIsReferenced( enumClass.typeParams, originalTparams, originalVparamss, parents) if (originalTparams.isEmpty && (parents.isEmpty || tparamReferenced)) - derivedEnumParams.map(tdef => tdef.withFlags(tdef.mods.flags | PrivateLocal.toFlags)) + derivedEnumParams.map(tdef => tdef.withFlags(tdef.mods.flags | PrivateLocal)) else originalTparams } else originalTparams @@ -974,7 +974,7 @@ object desugar { case _ => val tmpName = UniqueName.fresh() val patMods = - mods & Lazy | Synthetic | (if (ctx.owner.isClass) PrivateLocal.toFlags else EmptyFlags) + mods & Lazy | Synthetic | (if (ctx.owner.isClass) PrivateLocal else EmptyFlags) val firstDef = ValDef(tmpName, TypeTree(), matchExpr) .withSpan(pat.span.union(rhs.span)).withMods(patMods) diff --git a/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala b/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala index e63cfb79fb82..59dd65fef043 100644 --- a/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala +++ b/compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala @@ -286,7 +286,7 @@ object DesugarEnums { val toStringDef = toStringMethLit(name.toString) val impl1 = cpy.Template(impl)(body = List(ordinalDef, toStringDef) ++ registerCall) .withAttachment(ExtendsSingletonMirror, ()) - val vdef = ValDef(name, TypeTree(), New(impl1)).withMods(mods | EnumValue.toFlags) + val vdef = ValDef(name, TypeTree(), New(impl1)).withMods(mods | EnumValue) flatTree(scaffolding ::: vdef :: Nil).withSpan(span) } } @@ -302,7 +302,7 @@ object DesugarEnums { else { val (tag, scaffolding) = nextOrdinal(CaseKind.Simple) val creator = Apply(Ident(nme.DOLLAR_NEW), List(Literal(Constant(tag)), Literal(Constant(name.toString)))) - val vdef = ValDef(name, enumClassRef, creator).withMods(mods | EnumValue.toFlags) + val vdef = ValDef(name, enumClassRef, creator).withMods(mods | EnumValue) flatTree(scaffolding ::: vdef :: Nil).withSpan(span) } } diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index 330edc6005ed..4e594cd2a771 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -866,7 +866,7 @@ object Trees { class EmptyValDef[T >: Untyped] extends ValDef[T]( nme.WILDCARD, genericEmptyTree[T], genericEmptyTree[T])(NoSource) with WithoutTypeOrPos[T] { myTpe = NoType.asInstanceOf[T] - setMods(untpd.Modifiers(PrivateLocal.toFlags)) + setMods(untpd.Modifiers(PrivateLocal)) override def isEmpty: Boolean = true override def withSpan(span: Span) = throw new AssertionError("Cannot change span of EmptyValDef") } diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index 104d26ab3b23..a0ce58fc9112 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -415,7 +415,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { makeConstructor(Nil, Nil) def makeSelfDef(name: TermName, tpt: Tree)(implicit ctx: Context): ValDef = - ValDef(name, tpt, EmptyTree).withFlags(PrivateLocal.toFlags) + ValDef(name, tpt, EmptyTree).withFlags(PrivateLocal) def makeTupleOrParens(ts: List[Tree])(implicit ctx: Context): Tree = ts match { case t :: Nil => Parens(t) @@ -437,7 +437,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { vdef.withMods(mods | Param) } - def makeSyntheticParameter(n: Int = 1, tpt: Tree = null, flags: FlagSet = SyntheticTermParam.toFlags)(implicit ctx: Context): ValDef = + def makeSyntheticParameter(n: Int = 1, tpt: Tree = null, flags: FlagSet = SyntheticTermParam)(implicit ctx: Context): ValDef = ValDef(nme.syntheticParamName(n), if (tpt == null) TypeTree() else tpt, EmptyTree) .withFlags(flags) diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 57098a0c89cf..6d345a1550cc 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -325,7 +325,7 @@ class Definitions { Object_finalize, Object_notify, Object_notifyAll, Object_wait, Object_waitL, Object_waitLI) @threadUnsafe lazy val AnyKindClass: ClassSymbol = { - val cls = ctx.newCompleteClassSymbol(ScalaPackageClass, tpnme.AnyKind, AbstractFinal.toFlags | Permanent, Nil) + val cls = ctx.newCompleteClassSymbol(ScalaPackageClass, tpnme.AnyKind, AbstractFinal | Permanent, Nil) if (!ctx.settings.YnoKindPolymorphism.value) { // Enable kind-polymorphism by exposing scala.AnyKind cls.entered @@ -348,11 +348,11 @@ class Definitions { MethodType(List(ThrowableType), NothingType)) @threadUnsafe lazy val NothingClass: ClassSymbol = enterCompleteClassSymbol( - ScalaPackageClass, tpnme.Nothing, AbstractFinal.toFlags, List(AnyClass.typeRef)) + ScalaPackageClass, tpnme.Nothing, AbstractFinal, List(AnyClass.typeRef)) def NothingType: TypeRef = NothingClass.typeRef @threadUnsafe lazy val RuntimeNothingModuleRef: TermRef = ctx.requiredModuleRef("scala.runtime.Nothing") @threadUnsafe lazy val NullClass: ClassSymbol = enterCompleteClassSymbol( - ScalaPackageClass, tpnme.Null, AbstractFinal.toFlags, List(ObjectClass.typeRef)) + ScalaPackageClass, tpnme.Null, AbstractFinal, List(ObjectClass.typeRef)) def NullType: TypeRef = NullClass.typeRef @threadUnsafe lazy val RuntimeNullModuleRef: TermRef = ctx.requiredModuleRef("scala.runtime.Null") diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 235dc81febf4..24eb3bac0d93 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -1109,7 +1109,7 @@ object Denotations { final def filterDisjoint(denots: PreDenotation)(implicit ctx: Context): SingleDenotation = if (denots.exists && denots.matches(this)) NoDenotation else this def filterWithFlags(required: FlagConjunction, excluded: FlagSet)(implicit ctx: Context): SingleDenotation = - if (required.toFlags.isEmpty && excluded.isEmpty || compatibleWith(required, excluded)) this else NoDenotation + if (required.isEmpty && excluded.isEmpty || compatibleWith(required, excluded)) this else NoDenotation type AsSeenFromResult = SingleDenotation protected def computeAsSeenFrom(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 63205e6312e2..c80b6964a70e 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -135,16 +135,8 @@ object Flags { def termFlagSet(x: Long) = FlagSet(TERMS | x) - /** A class representing flag sets that should be tested - * conjunctively. I.e. for a flag conjunction `fc`, - * `x is fc` tests whether `x` contains all flags in `fc`. - */ - case class FlagConjunction(bits: Long) { - def toFlags = FlagSet(bits) - def flagsString: String = toFlags.flagsString - def | (fs: FlagSet): FlagConjunction = FlagConjunction((toFlags | fs).bits) - } - + type FlagConjunction = FlagSet + def FlagConjunction(bits: Long) = FlagSet(bits) def termFlagConjunction(x: Long) = FlagConjunction(TERMS | x) private final val TYPESHIFT = 2 diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 166cef8bdb0a..b58f3d9978e6 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -208,13 +208,13 @@ object SymDenotations { /** Has this denotation all of the flags in `fs` set? */ final def isAllOf(fs: FlagConjunction)(implicit ctx: Context): Boolean = - (if (isCurrent(fs.toFlags)) myFlags else flags).isAllOf(fs) + (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: FlagConjunction, butNot: FlagSet)(implicit ctx: Context): Boolean = - (if (isCurrent(fs.toFlags) && isCurrent(butNot)) myFlags else flags).isAllOf(fs, butNot) + (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 cefb511a991b..63b024c53eba 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -296,11 +296,11 @@ trait Symbols { this: Context => /** Create a new skolem symbol. This is not the same as SkolemType, even though the * motivation (create a singleton referencing to a type) is similar. */ - def newSkolem(tp: Type): TermSymbol = newSymbol(defn.RootClass, nme.SKOLEM, SyntheticArtifact.toFlags | NonMember | Permanent, tp) + def newSkolem(tp: Type): TermSymbol = newSymbol(defn.RootClass, nme.SKOLEM, SyntheticArtifact | NonMember | Permanent, tp) def newErrorSymbol(owner: Symbol, name: Name, msg: => Message): Symbol = { val errType = ErrorType(msg) - newSymbol(owner, name, SyntheticArtifact.toFlags, + newSymbol(owner, name, SyntheticArtifact, if (name.isTypeName) TypeAlias(errType) else errType) } diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 177dc7f6c559..abf516715406 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -185,8 +185,8 @@ class ClassfileParser( if (isEnum) { instanceScope.toList.map(_.ensureCompleted()) staticScope.toList.map(_.ensureCompleted()) - classRoot.setFlag(Flags.JavaEnum.toFlags) - moduleRoot.setFlag(Flags.JavaEnum.toFlags) + classRoot.setFlag(Flags.JavaEnum) + moduleRoot.setFlag(Flags.JavaEnum) } result @@ -276,7 +276,7 @@ class ClassfileParser( if (!enumClass.exists) ctx.warning(s"no linked class for java enum $sym in ${sym.owner}. A referencing class file might be missing an InnerClasses entry.") else { - if (!enumClass.is(Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed.toFlags) + if (!enumClass.is(Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed) enumClass.addAnnotation(Annotation.Child(sym)) } } @@ -555,7 +555,7 @@ class ClassfileParser( if (ctx.debug && ctx.verbose) println("" + sym + "; signature = " + sig + " type = " + newType) case tpnme.SyntheticATTR => - sym.setFlag(Flags.SyntheticArtifact.toFlags) + sym.setFlag(Flags.SyntheticArtifact) case tpnme.BridgeATTR => sym.setFlag(Flags.Bridge) case tpnme.DeprecatedATTR => diff --git a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala index d56a12dcb02c..132b1648be0d 100644 --- a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala @@ -120,7 +120,7 @@ object JavaParsers { // This also avoids clashes between the constructor parameter names and member names. if (needsDummyConstr) { stats1 = constr1 :: stats1 - constr1 = makeConstructor(List(scalaDot(tpnme.Unit)), tparams, Flags.JavaDefined | Flags.PrivateLocal.toFlags) + constr1 = makeConstructor(List(scalaDot(tpnme.Unit)), tparams, Flags.JavaDefined | Flags.PrivateLocal) } Template(constr1.asInstanceOf[DefDef], parents, Nil, EmptyValDef, stats1) } @@ -401,7 +401,7 @@ object JavaParsers { throw new RuntimeException } - def typeParams(flags: FlagSet = Flags.JavaDefined | Flags.PrivateLocal.toFlags | Flags.Param): List[TypeDef] = + def typeParams(flags: FlagSet = Flags.JavaDefined | Flags.PrivateLocal | Flags.Param): List[TypeDef] = if (in.token == LT) { in.nextToken() val tparams = repsep(() => typeParam(flags), COMMA) @@ -711,7 +711,7 @@ object JavaParsers { val iface = atSpan(start, nameOffset) { TypeDef( name, - makeTemplate(parents, body, tparams, false)).withMods(mods | Flags.Trait | Flags.JavaInterface.toFlags | Flags.Abstract) + makeTemplate(parents, body, tparams, false)).withMods(mods | Flags.Trait | Flags.JavaInterface | Flags.Abstract) } addCompanionObject(statics, iface) } @@ -835,7 +835,7 @@ object JavaParsers { Select(New(javaLangDot(tpnme.Enum)), nme.CONSTRUCTOR), List(enumType)), Nil) val enumclazz = atSpan(start, nameOffset) { TypeDef(name, - makeTemplate(superclazz :: interfaces, body, List(), true)).withMods(mods | Flags.JavaEnum.toFlags) + makeTemplate(superclazz :: interfaces, body, List(), true)).withMods(mods | Flags.JavaEnum) } addCompanionObject(consts ::: statics ::: predefs, enumclazz) } @@ -854,7 +854,7 @@ object JavaParsers { skipAhead() accept(RBRACE) } - ValDef(name.toTermName, enumType, unimplementedExpr).withMods(Modifiers(Flags.JavaEnum.toFlags | Flags.StableRealizable | Flags.JavaDefined | Flags.JavaStatic)) + ValDef(name.toTermName, enumType, unimplementedExpr).withMods(Modifiers(Flags.JavaEnum | Flags.StableRealizable | Flags.JavaDefined | Flags.JavaStatic)) } } diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index ef6ac80fd743..b1488faacef1 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1609,7 +1609,7 @@ object Parsers { case USCORE => val start = in.skipToken() val pname = WildcardParamName.fresh() - val param = ValDef(pname, TypeTree(), EmptyTree).withFlags(SyntheticTermParam.toFlags) + val param = ValDef(pname, TypeTree(), EmptyTree).withFlags(SyntheticTermParam) .withSpan(Span(start)) placeholderParams = param :: placeholderParams atSpan(start) { Ident(pname) } @@ -2178,7 +2178,7 @@ object Parsers { val start = in.offset val mods = annotsAsMods() | { - if (ownerKind == ParamOwner.Class) Param | PrivateLocal.toFlags + if (ownerKind == ParamOwner.Class) Param | PrivateLocal else Param } | { if (ownerKind == ParamOwner.Def) EmptyFlags @@ -2243,7 +2243,7 @@ object Parsers { if (!(mods.flags &~ (ParamAccessor | Inline | impliedMods.flags)).isEmpty) syntaxError("`val' or `var' expected") if (firstClause && ofCaseClass) mods - else mods | PrivateLocal.toFlags + else mods | PrivateLocal } } else { @@ -2763,7 +2763,7 @@ object Parsers { /** EnumCase = `case' (id ClassConstr [`extends' ConstrApps] | ids) */ def enumCase(start: Offset, mods: Modifiers): DefTree = { - val mods1 = mods | EnumCase.toFlags + val mods1 = mods | EnumCase in.skipCASE() atSpan(start, nameStart) { @@ -2822,9 +2822,9 @@ object Parsers { } else { newLineOptWhenFollowedBy(LBRACE) - val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal.toFlags)) + val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal)) val vparamss1 = vparamss.map(_.map(vparam => - vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal.toFlags))) + vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal))) val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil) if (tparams.isEmpty && vparamss.isEmpty) ModuleDef(name, templ) else TypeDef(name.toTypeName, templ) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index 841866fd03e1..2e6f0565ca27 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -1722,7 +1722,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. def Flags_ParamAccessor: Flags = core.Flags.ParamAccessor def Flags_Enum: Flags = core.Flags.Enum def Flags_ModuleClass: Flags = core.Flags.ModuleClass - def Flags_PrivateLocal: Flags = core.Flags.PrivateLocal.toFlags + def Flags_PrivateLocal: Flags = core.Flags.PrivateLocal def Flags_Package: Flags = core.Flags.Package // diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 5ab7b1fa9a0a..04fb8b6d9336 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -258,7 +258,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { var inlineFlag = InlineProxy if (paramtp.hasAnnotation(defn.InlineParamAnnot)) inlineFlag |= Inline val (bindingFlags, bindingType) = - if (isByName) (InlineByNameProxy.toFlags.toTermFlags, ExprType(argtpe.widen)) + if (isByName) (InlineByNameProxy.toTermFlags, ExprType(argtpe.widen)) else (inlineFlag, argtpe.widen) val boundSym = newSym(name, bindingFlags, bindingType).asTerm val binding = { diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 7218167b3ce2..d75f066b973c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -532,7 +532,7 @@ class Namer { typer: Typer => def addEnumConstants(mdef: DefTree, sym: Symbol)(implicit ctx: Context): Unit = mdef match { case vdef: ValDef if (isEnumConstant(vdef)) => val enumClass = sym.owner.linkedClass - if (!enumClass.is(Sealed)) enumClass.setFlag(Flags.AbstractSealed.toFlags) + if (!enumClass.is(Sealed)) enumClass.setFlag(Flags.AbstractSealed) addChild(enumClass, sym) case _ => } From d4cdf52da6196ad79b9d2bbb608e6dc28942a9f3 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 19 Jun 2019 14:08:27 +0200 Subject: [PATCH 10/25] fix runtime breakage after rebase --- .../src/dotty/tools/dotc/transform/AugmentScala2Traits.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala b/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala index 3d5267f8effc..75a439ac445d 100644 --- a/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala +++ b/compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala @@ -56,7 +56,7 @@ class AugmentScala2Traits extends MiniPhase with IdentityDenotTransformer { this info = MethodType(getter.info.resultType :: Nil, defn.UnitType)) for (sym <- mixin.info.decls) { - if (sym.isGetter && !sym.is(LazyOrDeferred) && !sym.setter.exists && + if (sym.isGetter && !sym.isOneOf(LazyOrDeferred) && !sym.setter.exists && !sym.info.resultType.isInstanceOf[ConstantType]) traitSetter(sym.asTerm).enteredAfter(thisPhase) if ((sym.isAllOf(PrivateAccessor) && !sym.name.is(ExpandedName) && From 2f9250d0c5c49154b3cb4244dbfa321e5705d365 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 19 Jun 2019 14:28:36 +0200 Subject: [PATCH 11/25] Drop allOf --- compiler/src/dotty/tools/dotc/ast/untpd.scala | 2 +- .../src/dotty/tools/dotc/core/Flags.scala | 99 ++++++++----------- .../tools/dotc/interactive/Completion.scala | 2 +- .../tools/dotc/tastyreflect/KernelImpl.scala | 2 +- .../tools/dotc/transform/Constructors.scala | 2 +- .../dotc/transform/LinkScala2Impls.scala | 2 +- .../src/dotty/tools/dotc/typer/Checking.scala | 2 +- .../src/dotty/tools/repl/ReplDriver.scala | 2 +- .../tools/dottydoc/core/DocASTPhase.scala | 2 +- 9 files changed, 50 insertions(+), 65 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index a0ce58fc9112..c8c0bd36272d 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -217,7 +217,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { else { if (ms.nonEmpty) for (m <- ms) - assert(flags.isAllOf(allOf(m.flags)) || + assert(flags.isAllOf(m.flags) || m.isInstanceOf[Mod.Private] && !privateWithin.isEmpty, s"unaccounted modifier: $m in $this when adding $ms") copy(mods = ms) diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index c80b6964a70e..1978c3ec8978 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -64,7 +64,7 @@ object Flags { /** Does this flag set have all of the flags in given flag conjunction? * Pre: The intersection of the typeflags of both sets must be non-empty. */ - def isAllOf(flags: FlagConjunction): Boolean = { + def isAllOf(flags: FlagSet): Boolean = { val fs = bits & flags.bits ((fs & KINDFLAGS) != 0 || flags.bits == 0) && (fs >>> TYPESHIFT) == (flags.bits >>> TYPESHIFT) @@ -74,7 +74,7 @@ object Flags { * and at the same time contain none of the flags in the `butNot` set? * Pre: The intersection of the typeflags of both sets must be non-empty. */ - def isAllOf(flags: FlagConjunction, butNot: FlagSet): Boolean = isAllOf(flags) && !is(butNot) + def isAllOf(flags: FlagSet, butNot: FlagSet): Boolean = isAllOf(flags) && !isOneOf(butNot) def isEmpty: Boolean = (bits & ~KINDFLAGS) == 0 @@ -191,21 +191,6 @@ object Flags { flag } - def allOf(flags: FlagSet) = FlagConjunction(flags.bits) - - /** The conjunction of all flags in given flag set */ - def allOf(flags1: FlagSet, flags2: FlagSet): FlagConjunction = { - assert(flags1.numFlags == 1 && flags2.numFlags == 1, "Flags.allOf doesn't support flag " + (if (flags1.numFlags != 1) flags1 else flags2)) - FlagConjunction((flags1 | flags2).bits) - } - - /** The conjunction of all flags in given flag set */ - def allOf(flags1: FlagSet, flags2: FlagSet, flags3: FlagSet, flagss: FlagSet*): FlagConjunction = { - val flags0 = allOf(flags1, flags2) | flags3 - assert(flags3.numFlags == 1 && flagss.forall(_.numFlags == 1), "Flags.allOf doesn't support flag " + (if (flags3.numFlags != 1) flags3 else flagss.find(_.numFlags != 1))) - FlagConjunction((flags0 | union(flagss: _*)).bits) - } - def commonFlags(flagss: FlagSet*): FlagSet = union(flagss.map(_.toCommonFlags): _*) /** The empty flag set */ @@ -604,28 +589,28 @@ object Flags { final val EffectivelyFinalFlags: FlagSet = Private | Final /** A private method */ - final val PrivateMethod: FlagConjunction = allOf(Private, Method) + final val PrivateMethod: FlagConjunction = Private | Method /** A private accessor */ - final val PrivateAccessor: FlagConjunction = allOf(Private, Accessor) + final val PrivateAccessor: FlagConjunction = Private | Accessor /** An inline method */ - final val InlineMethod: FlagConjunction = allOf(Inline, Method) + final val InlineMethod: FlagConjunction = Inline | Method /** An inline by-name parameter proxy */ - final val InlineByNameProxy: FlagConjunction = allOf(InlineProxy, Method) + final val InlineByNameProxy: FlagConjunction = InlineProxy | Method /** An inline parameter */ - final val InlineParam: FlagConjunction = allOf(Inline, Param) + final val InlineParam: FlagConjunction = Inline | Param /** An extension method */ - final val ExtensionMethod = allOf(Extension, Method) + final val ExtensionMethod = Extension | Method /** An implied method */ - final val SyntheticImpliedMethod: FlagConjunction = allOf(Synthetic, Implied, Method) + final val SyntheticImpliedMethod: FlagConjunction = Synthetic | Implied | Method /** An enum case */ - final val EnumCase: FlagConjunction = allOf(Enum, Case) + final val EnumCase: FlagConjunction = Enum | Case /** A term parameter or parameter accessor */ final val TermParamOrAccessor: FlagSet = Param | ParamAccessor @@ -652,10 +637,10 @@ object Flags { final val FinalOrSealed: FlagSet = Final | Sealed /** A covariant type parameter instance */ - final val LocalCovariant: FlagConjunction = allOf(Local, Covariant) + final val LocalCovariant: FlagConjunction = Local | Covariant /** A contravariant type parameter instance */ - final val LocalContravariant: FlagConjunction = allOf(Local, Contravariant) + final val LocalContravariant: FlagConjunction = Local | Contravariant /** Has defined or inherited default parameters */ final val HasDefaultParamsFlags: FlagSet = DefaultParameterized | InheritedDefaultParams @@ -664,74 +649,74 @@ object Flags { final val ValidForeverFlags: FlagSet = Package | Permanent | Scala2ExistentialCommon /** A type parameter of a class or trait */ - final val ClassTypeParam: FlagConjunction = allOf(TypeParam, Private) + final val ClassTypeParam: FlagConjunction = TypeParam | Private /** Is a default parameter in Scala 2*/ - final val DefaultParameter: FlagConjunction = allOf(Param, DefaultParameterized) + final val DefaultParameter: FlagConjunction = Param | DefaultParameterized /** A trait that does not need to be initialized */ - final val NoInitsTrait: FlagConjunction = allOf(Trait, NoInits) + final val NoInitsTrait: FlagConjunction = Trait | NoInits /** A Java interface, potentially with default methods */ - final val JavaTrait: FlagConjunction = allOf(JavaDefined, Trait, NoInits) + final val JavaTrait: FlagConjunction = JavaDefined | Trait | NoInits /** A Java interface */ // TODO when unpickling, reconstitute from context - final val JavaInterface: FlagConjunction = allOf(JavaDefined, Trait) + final val JavaInterface: FlagConjunction = JavaDefined | Trait /** A Java companion object */ - final val JavaModule: FlagConjunction = allOf(JavaDefined, Module) + final val JavaModule: FlagConjunction = JavaDefined | Module /** A Java companion object */ - final val JavaProtected: FlagConjunction = allOf(JavaDefined, Protected) + final val JavaProtected: FlagConjunction = JavaDefined | Protected /** A Java enum */ - final val JavaEnum: FlagConjunction = allOf(JavaDefined, Enum) + final val JavaEnum: FlagConjunction = JavaDefined | Enum /** A Java enum trait */ - final val JavaEnumTrait: FlagConjunction = allOf(JavaDefined, Enum) + final val JavaEnumTrait: FlagConjunction = JavaDefined | Enum /** A Java enum value */ - final val JavaEnumValue: FlagConjunction = allOf(StableRealizable, JavaStatic, JavaDefined, Enum) + final val JavaEnumValue: FlagConjunction = StableRealizable | JavaStatic | JavaDefined | Enum /** An enum value */ - final val EnumValue: FlagConjunction = allOf(StableRealizable, JavaStatic, Enum) + final val EnumValue: FlagConjunction = (StableRealizable | JavaStatic | Enum) /** Labeled private[this] */ - final val PrivateLocal: FlagConjunction = allOf(Private, Local) + final val PrivateLocal: FlagConjunction = Private | Local /** A private[this] parameter accessor */ - final val PrivateLocalParamAccessor: FlagConjunction = allOf(Private, Local, ParamAccessor) + final val PrivateLocalParamAccessor: FlagConjunction = Private | Local | ParamAccessor /** A parameter forwarder */ - final val ParamForwarder: FlagConjunction = allOf(Method, StableRealizable, ParamAccessor) + final val ParamForwarder: FlagConjunction = Method | StableRealizable | ParamAccessor /** A private[this] parameter */ - final val PrivateLocalParam: FlagConjunction = allOf(Private, Local, Param) + final val PrivateLocalParam: FlagConjunction = Private | Local | Param /** A private parameter accessor */ - final val PrivateParamAccessor: FlagConjunction = allOf(Private, ParamAccessor) + final val PrivateParamAccessor: FlagConjunction = Private | ParamAccessor /** A local parameter */ - final val ParamAndLocal: FlagConjunction = allOf(Param, Local) + final val ParamAndLocal: FlagConjunction = Param | Local /** Labeled protected[this] */ - final val ProtectedLocal: FlagConjunction = allOf(Protected, Local) + final val ProtectedLocal: FlagConjunction = Protected | Local - final val LiftedMethod: FlagConjunction = allOf(Lifted, Method) + final val LiftedMethod: FlagConjunction = Lifted | Method /** Java symbol which is `protected` and `static` */ - final val StaticProtected: FlagConjunction = allOf(JavaDefined, Protected, JavaStatic) + final val StaticProtected: FlagConjunction = JavaDefined | Protected | JavaStatic - final val Scala2Trait: FlagConjunction = allOf(Scala2x, Trait) + final val Scala2Trait: FlagConjunction = Scala2x | Trait - final val AbstractFinal: FlagConjunction = allOf(Abstract, Final) - final val AbstractSealed: FlagConjunction = allOf(Abstract, Sealed) - final val AbstractAndOverride: FlagConjunction = allOf(Abstract, Override) + final val AbstractFinal: FlagConjunction = Abstract | Final + final val AbstractSealed: FlagConjunction = Abstract | Sealed + final val AbstractAndOverride: FlagConjunction = Abstract | Override - final val SyntheticArtifact: FlagConjunction = allOf(Synthetic, Artifact) - final val SyntheticModule: FlagConjunction = allOf(Synthetic, Module) - final val SyntheticTermParam: FlagConjunction = allOf(Synthetic, TermParam) - final val SyntheticTypeParam: FlagConjunction = allOf(Synthetic, TypeParam) - final val SyntheticCase: FlagConjunction = allOf(Synthetic, Case) - final val SyntheticOpaque: FlagConjunction = allOf(Synthetic, Opaque) + final val SyntheticArtifact: FlagConjunction = Synthetic | Artifact + final val SyntheticModule: FlagConjunction = Synthetic | Module + final val SyntheticTermParam: FlagConjunction = Synthetic | TermParam + final val SyntheticTypeParam: FlagConjunction = Synthetic | TypeParam + final val SyntheticCase: FlagConjunction = Synthetic | Case + final val SyntheticOpaque: FlagConjunction = Synthetic | Opaque } diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index c1dcc5bb29f6..7a35ce87b1ad 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -255,7 +255,7 @@ object Completion { !sym.isPrimaryConstructor && sym.sourceSymbol.exists && (!sym.is(Package) || sym.is(ModuleClass)) && - !sym.isAllOf(allOf(Mutable, Accessor)) && + !sym.isAllOf(Mutable | Accessor) && !sym.isPackageObject && !sym.is(Artifact) && ( diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index 2e6f0565ca27..b1d68bf44036 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -1680,7 +1680,7 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util. type Flags = core.Flags.FlagSet /** Is the given flag set a subset of this flag sets */ - def Flags_is(self: Flags)(that: Flags): Boolean = self.isAllOf(allOf(that)) + def Flags_is(self: Flags)(that: Flags): Boolean = self.isAllOf(that) /** Union of the two flag sets */ def Flags_or(self: Flags)(that: Flags): Flags = self | that diff --git a/compiler/src/dotty/tools/dotc/transform/Constructors.scala b/compiler/src/dotty/tools/dotc/transform/Constructors.scala index 3cf141ecd6b0..05c9e545ba2a 100644 --- a/compiler/src/dotty/tools/dotc/transform/Constructors.scala +++ b/compiler/src/dotty/tools/dotc/transform/Constructors.scala @@ -121,7 +121,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase = private def mightBeDropped(sym: Symbol)(implicit ctx: Context) = sym.is(Private, butNot = MethodOrLazy) && !sym.isAllOf(MutableParamAccessor) - private final val MutableParamAccessor = allOf(Mutable, ParamAccessor) + private final val MutableParamAccessor = Mutable | ParamAccessor override def transformTemplate(tree: Template)(implicit ctx: Context): Tree = { val cls = ctx.owner.asClass diff --git a/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala b/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala index a6a21fe2499f..aafdc8968ab6 100644 --- a/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala +++ b/compiler/src/dotty/tools/dotc/transform/LinkScala2Impls.scala @@ -98,5 +98,5 @@ class LinkScala2Impls extends MiniPhase with IdentityDenotTransformer { thisPhas else throw new AssertionError(i"no impl method for $meth") } - private val Scala2xTrait = allOf(Scala2x, Trait) + private val Scala2xTrait = Scala2x | Trait } diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 66fb90ce05cb..9efcc00b0a5e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -392,7 +392,7 @@ object Checking { if (sym.isOneOf(flag)) fail(AbstractMemberMayNotHaveModifier(sym, flag)) def checkNoConflict(flag1: FlagSet, flag2: FlagSet, msg: => String) = - if (sym.isAllOf(allOf(flag1, flag2))) fail(msg) + if (sym.isAllOf(flag1 | flag2)) fail(msg) def checkCombination(flag1: FlagSet, flag2: FlagSet) = checkNoConflict(flag1, flag2, i"illegal combination of modifiers: `$flag1` and `$flag2` for: $sym") def checkApplicable(flag: FlagSet, ok: Boolean) = diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index 5c7a95aba801..136f8652df56 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -251,7 +251,7 @@ class ReplDriver(settings: Array[String], val info = symbol.info val defs = info.bounds.hi.finalResultType - .membersBasedOnFlags(required = allOf(Method), excluded = Accessor | ParamAccessor | Synthetic | Private) + .membersBasedOnFlags(required = Method, excluded = Accessor | ParamAccessor | Synthetic | Private) .filterNot { denot => denot.symbol.owner == defn.AnyClass || denot.symbol.owner == defn.ObjectClass || diff --git a/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala b/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala index dec35d6c44c2..27e0716cd6de 100644 --- a/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala +++ b/doc-tool/src/dotty/tools/dottydoc/core/DocASTPhase.scala @@ -44,7 +44,7 @@ class DocASTPhase extends Phase { def membersFromSymbol(sym: Symbol): List[Entity] = { if (sym.info.exists) { - val defs = sym.info.bounds.hi.finalResultType.membersBasedOnFlags(Flags.allOf(Flags.Method), Flags.Synthetic | Flags.Private) + val defs = sym.info.bounds.hi.finalResultType.membersBasedOnFlags(Flags.Method, Flags.Synthetic | Flags.Private) .filterNot(_.symbol.owner.name.show == "Any") .map { meth => DefImpl( From 2537cb253ece6f7feaf2f2106595e8110e6c505a Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 19 Jun 2019 14:45:34 +0200 Subject: [PATCH 12/25] Drop FlagConjunction --- .../backend/jvm/DottyBackendInterface.scala | 4 +- compiler/src/dotty/tools/dotc/ast/untpd.scala | 2 +- .../dotty/tools/dotc/core/Denotations.scala | 10 +-- .../src/dotty/tools/dotc/core/Flags.scala | 84 +++++++++---------- .../tools/dotc/core/SymDenotations.scala | 6 +- .../src/dotty/tools/dotc/core/Types.scala | 12 +-- .../tools/dotc/transform/patmat/Space.scala | 4 +- .../src/dotty/tools/dotc/typer/Namer.scala | 2 +- .../dotty/tools/dotc/typer/TypeAssigner.scala | 2 +- .../src/dotty/tools/dotc/typer/Typer.scala | 4 +- compiler/test/worksheets/flagtest.sc | 8 +- docs/docs/internals/dotc-scalac.md | 4 - 12 files changed, 66 insertions(+), 76 deletions(-) diff --git a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index 8f271469d732..acc9c4667a49 100644 --- a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -3,7 +3,7 @@ package dotty.tools.backend.jvm import dotty.tools.dotc.ast.tpd import dotty.tools.dotc.ast.Trees import dotty.tools.dotc -import dotty.tools.dotc.core.Flags.{termFlagSet, termFlagConjunction} +import dotty.tools.dotc.core.Flags.{termFlagSet} import dotty.tools.dotc.transform.{Erasure, GenericSignatures} import dotty.tools.dotc.transform.SymUtils._ import java.io.{File => _} @@ -881,7 +881,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma def =:=(other: Type): Boolean = tp =:= other def membersBasedOnFlags(excludedFlags: Flags, requiredFlags: Flags): List[Symbol] = - tp.membersBasedOnFlags(termFlagConjunction(requiredFlags), termFlagSet(excludedFlags)).map(_.symbol).toList + tp.membersBasedOnFlags(termFlagSet(requiredFlags), termFlagSet(excludedFlags)).map(_.symbol).toList def resultType: Type = tp.resultType diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index c8c0bd36272d..d55240d26bdc 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -187,7 +187,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { def is(fs: FlagSet, butNot: FlagSet): Boolean = flags.is(fs, butNot = butNot) def isOneOf(fs: FlagSet): Boolean = flags.isOneOf(fs) def isOneOf(fs: FlagSet, butNot: FlagSet): Boolean = flags.isOneOf(fs, butNot = butNot) - def isAllOf(fc: FlagConjunction): Boolean = flags.isAllOf(fc) + def isAllOf(fc: FlagSet): Boolean = flags.isAllOf(fc) def | (fs: FlagSet): Modifiers = withFlags(flags | fs) def & (fs: FlagSet): Modifiers = withFlags(flags & fs) diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 24eb3bac0d93..331d593a2644 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -113,7 +113,7 @@ object Denotations { /** Keep only those denotations in this group that have all of the flags in `required`, * but none of the flags in `excluded`. */ - def filterWithFlags(required: FlagConjunction, excluded: FlagSet)(implicit ctx: Context): PreDenotation + def filterWithFlags(required: FlagSet, excluded: FlagSet)(implicit ctx: Context): PreDenotation private[this] var cachedPrefix: Type = _ private[this] var cachedAsSeenFrom: AsSeenFromResult = _ @@ -260,7 +260,7 @@ object Denotations { * flags and no `excluded` flag, and produce a denotation that contains the type of the member * as seen from given prefix `pre`. */ - def findMember(name: Name, pre: Type, required: FlagConjunction, excluded: FlagSet)(implicit ctx: Context): Denotation = + def findMember(name: Name, pre: Type, required: FlagSet, excluded: FlagSet)(implicit ctx: Context): Denotation = info.findMember(name, pre, required, excluded) /** If this denotation is overloaded, filter with given predicate. @@ -1108,7 +1108,7 @@ object Denotations { if (p(this)) this else NoDenotation final def filterDisjoint(denots: PreDenotation)(implicit ctx: Context): SingleDenotation = if (denots.exists && denots.matches(this)) NoDenotation else this - def filterWithFlags(required: FlagConjunction, excluded: FlagSet)(implicit ctx: Context): SingleDenotation = + def filterWithFlags(required: FlagSet, excluded: FlagSet)(implicit ctx: Context): SingleDenotation = if (required.isEmpty && excluded.isEmpty || compatibleWith(required, excluded)) this else NoDenotation type AsSeenFromResult = SingleDenotation @@ -1147,7 +1147,7 @@ object Denotations { /** Does this denotation have all the `required` flags but none of the `excluded` flags? */ - private def compatibleWith(required: FlagConjunction, excluded: FlagSet)(implicit ctx: Context): Boolean = { + private def compatibleWith(required: FlagSet, excluded: FlagSet)(implicit ctx: Context): Boolean = { val symd: SymDenotation = this match { case symd: SymDenotation => symd case _ => symbol.denot @@ -1237,7 +1237,7 @@ object Denotations { derivedUnion(denot1 filterWithPredicate p, denot2 filterWithPredicate p) def filterDisjoint(denot: PreDenotation)(implicit ctx: Context): PreDenotation = derivedUnion(denot1 filterDisjoint denot, denot2 filterDisjoint denot) - def filterWithFlags(required: FlagConjunction, excluded: FlagSet)(implicit ctx: Context): PreDenotation = + def filterWithFlags(required: FlagSet, excluded: FlagSet)(implicit ctx: Context): PreDenotation = derivedUnion(denot1.filterWithFlags(required, excluded), denot2.filterWithFlags(required, excluded)) protected def derivedUnion(denot1: PreDenotation, denot2: PreDenotation) = if ((denot1 eq this.denot1) && (denot2 eq this.denot2)) this diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 1978c3ec8978..e7a4824d69bd 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -135,10 +135,6 @@ object Flags { def termFlagSet(x: Long) = FlagSet(TERMS | x) - type FlagConjunction = FlagSet - def FlagConjunction(bits: Long) = FlagSet(bits) - def termFlagConjunction(x: Long) = FlagConjunction(TERMS | x) - private final val TYPESHIFT = 2 private final val TERMindex = 0 private final val TYPEindex = 1 @@ -196,8 +192,6 @@ object Flags { /** The empty flag set */ final val EmptyFlags: FlagSet = FlagSet(0) - final val EmptyFlagConjunction = FlagConjunction(0) - /** The undefined flag set */ final val UndefinedFlags: FlagSet = FlagSet(~KINDFLAGS) @@ -589,28 +583,28 @@ object Flags { final val EffectivelyFinalFlags: FlagSet = Private | Final /** A private method */ - final val PrivateMethod: FlagConjunction = Private | Method + final val PrivateMethod: FlagSet = Private | Method /** A private accessor */ - final val PrivateAccessor: FlagConjunction = Private | Accessor + final val PrivateAccessor: FlagSet = Private | Accessor /** An inline method */ - final val InlineMethod: FlagConjunction = Inline | Method + final val InlineMethod: FlagSet = Inline | Method /** An inline by-name parameter proxy */ - final val InlineByNameProxy: FlagConjunction = InlineProxy | Method + final val InlineByNameProxy: FlagSet = InlineProxy | Method /** An inline parameter */ - final val InlineParam: FlagConjunction = Inline | Param + final val InlineParam: FlagSet = Inline | Param /** An extension method */ final val ExtensionMethod = Extension | Method /** An implied method */ - final val SyntheticImpliedMethod: FlagConjunction = Synthetic | Implied | Method + final val SyntheticImpliedMethod: FlagSet = Synthetic | Implied | Method /** An enum case */ - final val EnumCase: FlagConjunction = Enum | Case + final val EnumCase: FlagSet = Enum | Case /** A term parameter or parameter accessor */ final val TermParamOrAccessor: FlagSet = Param | ParamAccessor @@ -637,10 +631,10 @@ object Flags { final val FinalOrSealed: FlagSet = Final | Sealed /** A covariant type parameter instance */ - final val LocalCovariant: FlagConjunction = Local | Covariant + final val LocalCovariant: FlagSet = Local | Covariant /** A contravariant type parameter instance */ - final val LocalContravariant: FlagConjunction = Local | Contravariant + final val LocalContravariant: FlagSet = Local | Contravariant /** Has defined or inherited default parameters */ final val HasDefaultParamsFlags: FlagSet = DefaultParameterized | InheritedDefaultParams @@ -649,74 +643,74 @@ object Flags { final val ValidForeverFlags: FlagSet = Package | Permanent | Scala2ExistentialCommon /** A type parameter of a class or trait */ - final val ClassTypeParam: FlagConjunction = TypeParam | Private + final val ClassTypeParam: FlagSet = TypeParam | Private /** Is a default parameter in Scala 2*/ - final val DefaultParameter: FlagConjunction = Param | DefaultParameterized + final val DefaultParameter: FlagSet = Param | DefaultParameterized /** A trait that does not need to be initialized */ - final val NoInitsTrait: FlagConjunction = Trait | NoInits + final val NoInitsTrait: FlagSet = Trait | NoInits /** A Java interface, potentially with default methods */ - final val JavaTrait: FlagConjunction = JavaDefined | Trait | NoInits + final val JavaTrait: FlagSet = JavaDefined | Trait | NoInits /** A Java interface */ // TODO when unpickling, reconstitute from context - final val JavaInterface: FlagConjunction = JavaDefined | Trait + final val JavaInterface: FlagSet = JavaDefined | Trait /** A Java companion object */ - final val JavaModule: FlagConjunction = JavaDefined | Module + final val JavaModule: FlagSet = JavaDefined | Module /** A Java companion object */ - final val JavaProtected: FlagConjunction = JavaDefined | Protected + final val JavaProtected: FlagSet = JavaDefined | Protected /** A Java enum */ - final val JavaEnum: FlagConjunction = JavaDefined | Enum + final val JavaEnum: FlagSet = JavaDefined | Enum /** A Java enum trait */ - final val JavaEnumTrait: FlagConjunction = JavaDefined | Enum + final val JavaEnumTrait: FlagSet = JavaDefined | Enum /** A Java enum value */ - final val JavaEnumValue: FlagConjunction = StableRealizable | JavaStatic | JavaDefined | Enum + final val JavaEnumValue: FlagSet = StableRealizable | JavaStatic | JavaDefined | Enum /** An enum value */ - final val EnumValue: FlagConjunction = (StableRealizable | JavaStatic | Enum) + final val EnumValue: FlagSet = StableRealizable | JavaStatic | Enum /** Labeled private[this] */ - final val PrivateLocal: FlagConjunction = Private | Local + final val PrivateLocal: FlagSet = Private | Local /** A private[this] parameter accessor */ - final val PrivateLocalParamAccessor: FlagConjunction = Private | Local | ParamAccessor + final val PrivateLocalParamAccessor: FlagSet = Private | Local | ParamAccessor /** A parameter forwarder */ - final val ParamForwarder: FlagConjunction = Method | StableRealizable | ParamAccessor + final val ParamForwarder: FlagSet = Method | StableRealizable | ParamAccessor /** A private[this] parameter */ - final val PrivateLocalParam: FlagConjunction = Private | Local | Param + final val PrivateLocalParam: FlagSet = Private | Local | Param /** A private parameter accessor */ - final val PrivateParamAccessor: FlagConjunction = Private | ParamAccessor + final val PrivateParamAccessor: FlagSet = Private | ParamAccessor /** A local parameter */ - final val ParamAndLocal: FlagConjunction = Param | Local + final val ParamAndLocal: FlagSet = Param | Local /** Labeled protected[this] */ - final val ProtectedLocal: FlagConjunction = Protected | Local + final val ProtectedLocal: FlagSet = Protected | Local - final val LiftedMethod: FlagConjunction = Lifted | Method + final val LiftedMethod: FlagSet = Lifted | Method /** Java symbol which is `protected` and `static` */ - final val StaticProtected: FlagConjunction = JavaDefined | Protected | JavaStatic + final val StaticProtected: FlagSet = JavaDefined | Protected | JavaStatic - final val Scala2Trait: FlagConjunction = Scala2x | Trait + final val Scala2Trait: FlagSet = Scala2x | Trait - final val AbstractFinal: FlagConjunction = Abstract | Final - final val AbstractSealed: FlagConjunction = Abstract | Sealed - final val AbstractAndOverride: FlagConjunction = Abstract | Override + final val AbstractFinal: FlagSet = Abstract | Final + final val AbstractSealed: FlagSet = Abstract | Sealed + final val AbstractAndOverride: FlagSet = Abstract | Override - final val SyntheticArtifact: FlagConjunction = Synthetic | Artifact - final val SyntheticModule: FlagConjunction = Synthetic | Module - final val SyntheticTermParam: FlagConjunction = Synthetic | TermParam - final val SyntheticTypeParam: FlagConjunction = Synthetic | TypeParam - final val SyntheticCase: FlagConjunction = Synthetic | Case - final val SyntheticOpaque: FlagConjunction = Synthetic | Opaque + final val SyntheticArtifact: FlagSet = Synthetic | Artifact + final val SyntheticModule: FlagSet = Synthetic | Module + final val SyntheticTermParam: FlagSet = Synthetic | TermParam + final val SyntheticTypeParam: FlagSet = Synthetic | TypeParam + final val SyntheticCase: FlagSet = Synthetic | Case + final val SyntheticOpaque: FlagSet = Synthetic | Opaque } diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index b58f3d9978e6..c6e1f18b3d5c 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -207,13 +207,13 @@ object SymDenotations { (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: FlagConjunction)(implicit ctx: Context): Boolean = + 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: FlagConjunction, butNot: FlagSet)(implicit ctx: Context): Boolean = + 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 */ @@ -1758,7 +1758,7 @@ object SymDenotations { else collect(ownDenots, classParents) } - override final def findMember(name: Name, pre: Type, required: FlagConjunction, excluded: FlagSet)(implicit ctx: Context): Denotation = { + override final def findMember(name: Name, pre: Type, required: FlagSet, excluded: FlagSet)(implicit ctx: Context): Denotation = { val raw = if (excluded.is(Private)) nonPrivateMembersNamed(name) else membersNamed(name) raw.filterWithFlags(required, excluded).asSeenFrom(pre).toDenot(pre) } diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index fc8e3e8c1c1e..9adf3b58b9ee 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -519,7 +519,7 @@ object Types { */ @tailrec final def findDecl(name: Name, excluded: FlagSet)(implicit ctx: Context): Denotation = this match { case tp: ClassInfo => - tp.decls.denotsNamed(name).filterWithFlags(EmptyFlagConjunction, excluded).toDenot(NoPrefix) + tp.decls.denotsNamed(name).filterWithFlags(EmptyFlags, excluded).toDenot(NoPrefix) case tp: TypeProxy => tp.underlying.findDecl(name, excluded) case err: ErrorType => @@ -530,16 +530,16 @@ object Types { /** The member of this type with the given name */ final def member(name: Name)(implicit ctx: Context): Denotation = /*>|>*/ track("member") /*<|<*/ { - memberBasedOnFlags(name, required = EmptyFlagConjunction, excluded = EmptyFlags) + memberBasedOnFlags(name, required = EmptyFlags, excluded = EmptyFlags) } /** The non-private member of this type with the given name. */ final def nonPrivateMember(name: Name)(implicit ctx: Context): Denotation = track("nonPrivateMember") { - memberBasedOnFlags(name, required = EmptyFlagConjunction, excluded = Flags.Private) + memberBasedOnFlags(name, required = EmptyFlags, excluded = Flags.Private) } /** The member with given `name` and required and/or excluded flags */ - final def memberBasedOnFlags(name: Name, required: FlagConjunction = EmptyFlagConjunction, excluded: FlagSet = EmptyFlags)(implicit ctx: Context): Denotation = { + final def memberBasedOnFlags(name: Name, required: FlagSet = EmptyFlags, excluded: FlagSet = EmptyFlags)(implicit ctx: Context): Denotation = { // We need a valid prefix for `asSeenFrom` val pre = this match { case tp: ClassInfo => tp.appliedRef @@ -552,7 +552,7 @@ object Types { * flags and no `excluded` flag and produce a denotation that contains * the type of the member as seen from given prefix `pre`. */ - final def findMember(name: Name, pre: Type, required: FlagConjunction = EmptyFlagConjunction, excluded: FlagSet = EmptyFlags)(implicit ctx: Context): Denotation = { + final def findMember(name: Name, pre: Type, required: FlagSet = EmptyFlags, excluded: FlagSet = EmptyFlags)(implicit ctx: Context): Denotation = { @tailrec def go(tp: Type): Denotation = tp match { case tp: TermRef => go (tp.underlying match { @@ -813,7 +813,7 @@ object Types { } /** The set of members of this type that have all of `required` flags but none of `excluded` flags set. */ - final def membersBasedOnFlags(required: FlagConjunction, excluded: FlagSet)(implicit ctx: Context): Seq[SingleDenotation] = track("membersBasedOnFlags") { + final def membersBasedOnFlags(required: FlagSet, excluded: FlagSet)(implicit ctx: Context): Seq[SingleDenotation] = track("membersBasedOnFlags") { memberDenots(takeAllFilter, (name, buf) => buf ++= memberBasedOnFlags(name, required, excluded).alternatives) } diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 9a721bbee4d4..e51786b45fc5 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -629,8 +629,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { /** does the companion object of the given symbol have custom unapply */ def hasCustomUnapply(sym: Symbol): Boolean = { val companion = sym.companionModule - companion.findMember(nme.unapply, NoPrefix, required = EmptyFlagConjunction, excluded = Synthetic).exists || - companion.findMember(nme.unapplySeq, NoPrefix, required = EmptyFlagConjunction, excluded = Synthetic).exists + companion.findMember(nme.unapply, NoPrefix, required = EmptyFlags, excluded = Synthetic).exists || + companion.findMember(nme.unapplySeq, NoPrefix, required = EmptyFlags, excluded = Synthetic).exists } def doShow(s: Space, mergeList: Boolean = false): String = s match { diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index d75f066b973c..613392d37f7f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -45,7 +45,7 @@ trait NamerContextOps { this: Context => /** The denotation with the given `name` and all `required` flags in current context */ - def denotNamed(name: Name, required: FlagConjunction = EmptyFlagConjunction): Denotation = + def denotNamed(name: Name, required: FlagSet = EmptyFlags): Denotation = if (owner.isClass) if (outer.owner == owner) { // inner class scope; check whether we are referring to self if (scope.size == 1) { diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index e17c56b81b65..63f7adb2a7f1 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -53,7 +53,7 @@ trait TypeAssigner { def addRefinement(parent: Type, decl: Symbol) = { val inherited = parentType.findMember(decl.name, cls.thisType, - required = EmptyFlagConjunction, excluded = Private) + required = EmptyFlags, excluded = Private) .suchThat(decl.matches(_)) val inheritedInfo = inherited.info val isPolyFunctionApply = decl.name == nme.apply && (parent <:< defn.PolyFunctionType) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index accc44111bfb..21333feff274 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -122,7 +122,7 @@ class Typer extends Namer * @param required flags the result's symbol must have * @param posd indicates position to use for error reporting */ - def findRef(name: Name, pt: Type, required: FlagConjunction, posd: Positioned)(implicit ctx: Context): Type = { + def findRef(name: Name, pt: Type, required: FlagSet, posd: Positioned)(implicit ctx: Context): Type = { val refctx = ctx val noImports = ctx.mode.is(Mode.InPackageClauseName) @@ -394,7 +394,7 @@ class Typer extends Namer unimported = Set.empty foundUnderScala2 = NoType try { - var found = findRef(name, pt, EmptyFlagConjunction, tree.posd) + var found = findRef(name, pt, EmptyFlags, tree.posd) if (foundUnderScala2.exists && !(foundUnderScala2 =:= found)) { ctx.migrationWarning( ex"""Name resolution will change. diff --git a/compiler/test/worksheets/flagtest.sc b/compiler/test/worksheets/flagtest.sc index ac3a6ab13cc8..0533d6188748 100644 --- a/compiler/test/worksheets/flagtest.sc +++ b/compiler/test/worksheets/flagtest.sc @@ -2,16 +2,16 @@ package dotty.tools.dotc.core object flagtest { println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet - + import Flags._ - + val pri = Private //> pri : dotty.tools.dotc.core.Flags.FlagSet = private val pro = Protected //> pro : dotty.tools.dotc.core.Flags.FlagSet = protected val pripro = pri | pro //> pripro : dotty.tools.dotc.core.Flags.FlagSet = private protected pripro is pri //> res0: Boolean = true pripro is pro //> res1: Boolean = true pripro is Local //> res2: Boolean = false - val pp = allOf(pri, pro) //> pp : dotty.tools.dotc.core.Flags.FlagConjunction = private protected + val pp = allOf(pri, pro) //> pp : dotty.tools.dotc.core.Flags.FlagSet = private protected pripro is pp //> res3: Boolean = true pri is pp //> res4: Boolean = false pri is pripro //> res5: Boolean = true @@ -20,7 +20,7 @@ object flagtest { Method == Abstract //> res8: Boolean = false Method.toCommonFlags //> res9: dotty.tools.dotc.core.Flags.FlagSet = abstract FromStartFlags //> res10: dotty.tools.dotc.core.Flags.FlagSet = private protected

sealed module + //| aram> sealed module //| AccessFlags <= FromStartFlags //> res11: Boolean = true FromStartFlags <= AccessFlags //> res12: Boolean = false diff --git a/docs/docs/internals/dotc-scalac.md b/docs/docs/internals/dotc-scalac.md index 68e98beaa42c..409dbdf4ee48 100644 --- a/docs/docs/internals/dotc-scalac.md +++ b/docs/docs/internals/dotc-scalac.md @@ -73,10 +73,6 @@ if (sym is Flags.PackageClass) // dotc (*) * Example: `Module` is valid for both module values and module classes, `ModuleVal` / `ModuleClass` for either of the two. * `flags.is(Method | Param)`: true if `flags` has either of the two -* `flags.is(allOf(Method | Deferred))`: true if `flags` has both. `allOf` - creates a `FlagConjunction`, so a different overload of `is` is chosen. - - Careful: `flags.is(Method & Deferred)` is always true, because `Method & - Deferred` is empty. ### Tree ### * Trees don't have symbols From 31a247ecad63c879a561ab9780a209542cb7c435 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 19 Jun 2019 17:47:08 +0200 Subject: [PATCH 13/25] add crash diagnostics in ExtractDependencies --- compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala b/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala index 2390f7943a1d..e18085c1174a 100644 --- a/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala +++ b/compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala @@ -335,7 +335,7 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT /** Traverse the tree of a source file and record the dependencies and used names which * can be retrieved using `dependencies` and`usedNames`. */ - override def traverse(tree: Tree)(implicit ctx: Context): Unit = { + override def traverse(tree: Tree)(implicit ctx: Context): Unit = try { tree match { case Match(selector, _) => addPatMatDependency(selector.tpe) @@ -384,6 +384,10 @@ private class ExtractDependenciesCollector extends tpd.TreeTraverser { thisTreeT case _ => traverseChildren(tree) } + } catch { + case ex: AssertionError => + println(i"asserted failed while traversing $tree") + throw ex } /** Traverse a used type and record all the dependencies we need to keep track From c6b7b35e505c210e4d7d9c8bf62bc07ceb5b2691 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 19 Jun 2019 18:47:21 +0200 Subject: [PATCH 14/25] Make FlagSet an opaque type Make FlagSet an opaque type and all flag ops extension methods --- .../src/dotty/tools/dotc/core/Flags.scala | 153 ++++++++++-------- .../tools/dotc/core/SymDenotations.scala | 36 +++-- .../tools/dotc/printing/RefinedPrinter.scala | 8 +- 3 files changed, 111 insertions(+), 86 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index e7a4824d69bd..7a639b33184d 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -5,121 +5,132 @@ import language.implicitConversions object Flags { - /** A FlagSet represents a set of flags. Flags are encoded as follows: - * The first two bits indicate whether a flagset applies to terms, - * to types, or to both. Bits 2..63 are available for properties - * and can be doubly used for terms and types. - */ - case class FlagSet(val bits: Long) extends AnyVal { + object opaques { + + /** A FlagSet represents a set of flags. Flags are encoded as follows: + * The first two bits indicate whether a flagset applies to terms, + * to types, or to both. Bits 2..63 are available for properties + * and can be doubly used for terms and types. + */ + opaque type FlagSet = Long + def FlagSet(bits: Long): FlagSet = bits.asInstanceOf // !!! + def toBits(fs: FlagSet): Long = fs + } + type FlagSet = opaques.FlagSet + def FlagSet(bits: Long): FlagSet = opaques.FlagSet(bits) + + implicit object FlagOps { + + def (xs: FlagSet) bits: Long = opaques.toBits(xs) - /** The union of this flag set and the given flag set + /** The union of the given flag sets. * Combining two FlagSets with `|` will give a FlagSet * that has the intersection of the applicability to terms/types * of the two flag sets. It is checked that the intersection is not empty. */ - def | (that: FlagSet): FlagSet = - if (bits == 0) that - else if (that.bits == 0) this + def (x: FlagSet) | (that: FlagSet): FlagSet = + if (x.bits == 0) that + else if (that.bits == 0) x else { - val tbits = bits & that.bits & KINDFLAGS + val tbits = x.bits & that.bits & KINDFLAGS if (tbits == 0) - assert(false, s"illegal flagset combination: $this and $that") - FlagSet(tbits | ((this.bits | that.bits) & ~KINDFLAGS)) + assert(false, s"illegal flagset combination: $x and $that") + FlagSet(tbits | ((x.bits | that.bits) & ~KINDFLAGS)) } - /** The intersection of this flag set and the given flag set */ - def & (that: FlagSet): FlagSet = FlagSet(bits & that.bits) + /** The intersection of the given flag sets */ + def (x: FlagSet) & (that: FlagSet): FlagSet = FlagSet(x.bits & that.bits) - /** The intersection of this flag set with the complement of the given flag set */ - def &~ (that: FlagSet): FlagSet = { - val tbits = bits & KINDFLAGS - if ((tbits & that.bits) == 0) this - else FlagSet(tbits | ((this.bits & ~that.bits) & ~KINDFLAGS)) + /** The intersection of a flag set with the complement of another flag set */ + def (x: FlagSet) &~ (that: FlagSet): FlagSet = { + val tbits = x.bits & KINDFLAGS + if ((tbits & that.bits) == 0) x + else FlagSet(tbits | ((x.bits & ~that.bits) & ~KINDFLAGS)) } - def ^ (that: FlagSet) = - FlagSet((bits | that.bits) & KINDFLAGS | (bits ^ that.bits) & ~KINDFLAGS) + def (x: FlagSet) ^ (that: FlagSet) = + FlagSet((x.bits | that.bits) & KINDFLAGS | (x.bits ^ that.bits) & ~KINDFLAGS) - /** Does this flag set have a non-empty intersection with the given flag set? + /** Does a given flag set have a non-empty intersection with another flag set? * This means that both the kind flags and the carrier bits have non-empty intersection. */ - def is(flags: FlagSet): Boolean = { + def (x: FlagSet) is(flags: FlagSet): Boolean = { assert(flags.numFlags == 1) - val fs = bits & flags.bits + val fs = x.bits & flags.bits (fs & KINDFLAGS) != 0 && (fs & ~KINDFLAGS) != 0 } - /** Does this flag set have a non-empty intersection with the given flag set, + /** Does a given flag set have a non-empty intersection with another flag set, * and at the same time contain none of the flags in the `butNot` set? */ - def is(flags: FlagSet, butNot: FlagSet): Boolean = is(flags) && !isOneOf(butNot) + def (x: FlagSet) is(flags: FlagSet, butNot: FlagSet): Boolean = x.is(flags) && !x.isOneOf(butNot) - def isOneOf(flags: FlagSet): Boolean = { - val fs = bits & flags.bits + def (x: FlagSet) isOneOf(flags: FlagSet): Boolean = { + val fs = x.bits & flags.bits (fs & KINDFLAGS) != 0 && (fs & ~KINDFLAGS) != 0 } - def isOneOf(flags: FlagSet, butNot: FlagSet): Boolean = isOneOf(flags) && !isOneOf(butNot) + def (x: FlagSet) isOneOf(flags: FlagSet, butNot: FlagSet): Boolean = x.isOneOf(flags) && !x.isOneOf(butNot) - /** Does this flag set have all of the flags in given flag conjunction? - * Pre: The intersection of the typeflags of both sets must be non-empty. + /** Does a given flag set have all of the flags of another flag set? + * Pre: The intersection of the term/type flags of both sets must be non-empty. */ - def isAllOf(flags: FlagSet): Boolean = { - val fs = bits & flags.bits + def (x: FlagSet) isAllOf(flags: FlagSet): Boolean = { + val fs = x.bits & flags.bits ((fs & KINDFLAGS) != 0 || flags.bits == 0) && (fs >>> TYPESHIFT) == (flags.bits >>> TYPESHIFT) } - /** Does this flag set have all of the flags in given flag conjunction? + /** Does a given flag set have all of the flags in another flag set * and at the same time contain none of the flags in the `butNot` set? - * Pre: The intersection of the typeflags of both sets must be non-empty. + * Pre: The intersection of the term/type flags of both sets must be non-empty. */ - def isAllOf(flags: FlagSet, butNot: FlagSet): Boolean = isAllOf(flags) && !isOneOf(butNot) + def (x: FlagSet) isAllOf(flags: FlagSet, butNot: FlagSet): Boolean = x.isAllOf(flags) && !x.isOneOf(butNot) - def isEmpty: Boolean = (bits & ~KINDFLAGS) == 0 + def (x: FlagSet) isEmpty: Boolean = (x.bits & ~KINDFLAGS) == 0 - /** Is this flag set a subset of that one? */ - def <= (that: FlagSet): Boolean = (bits & that.bits) == bits + /** Is a given flag set a subset of another flag set? */ + def (x: FlagSet) <= (that: FlagSet): Boolean = (x.bits & that.bits) == x.bits - /** Does this flag set apply to terms? */ - def isTermFlags: Boolean = (bits & TERMS) != 0 + /** Does the given flag set apply to terms? */ + def (x: FlagSet) isTermFlags: Boolean = (x.bits & TERMS) != 0 - /** Does this flag set apply to terms? */ - def isTypeFlags: Boolean = (bits & TYPES) != 0 + /** Does the given flag set apply to terms? */ + def (x: FlagSet) isTypeFlags: Boolean = (x.bits & TYPES) != 0 - /** This flag set with all flags transposed to be type flags */ - def toTypeFlags: FlagSet = if (bits == 0) this else FlagSet(bits & ~KINDFLAGS | TYPES) + /** The given flag set with all flags transposed to be type flags */ + def (x: FlagSet) toTypeFlags: FlagSet = if (x.bits == 0) x else FlagSet(x.bits & ~KINDFLAGS | TYPES) - /** This flag set with all flags transposed to be term flags */ - def toTermFlags: FlagSet = if (bits == 0) this else FlagSet(bits & ~KINDFLAGS | TERMS) + /** The given flag set with all flags transposed to be term flags */ + def (x: FlagSet) toTermFlags: FlagSet = if (x.bits == 0) x else FlagSet(x.bits & ~KINDFLAGS | TERMS) - /** This flag set with all flags transposed to be common flags */ - def toCommonFlags: FlagSet = if (bits == 0) this else FlagSet(bits | KINDFLAGS) + /** The given flag set with all flags transposed to be common flags */ + def (x: FlagSet) toCommonFlags: FlagSet = if (x.bits == 0) x else FlagSet(x.bits | KINDFLAGS) - /** The number of non-kind flags in this set */ - def numFlags: Int = java.lang.Long.bitCount(bits & ~KINDFLAGS) + /** The number of non-kind flags in the given flag set */ + def (x: FlagSet) numFlags: Int = java.lang.Long.bitCount(x.bits & ~KINDFLAGS) - /** The lowest non-kind bit set in this flagset */ - def firstBit: Int = java.lang.Long.numberOfTrailingZeros(bits & ~KINDFLAGS) + /** The lowest non-kind bit set in the given flag set */ + def (x: FlagSet) firstBit: Int = java.lang.Long.numberOfTrailingZeros(x.bits & ~KINDFLAGS) - /** The list of non-empty names of flags with given index idx that are set in this FlagSet */ - private def flagString(idx: Int): List[String] = - if ((bits & (1L << idx)) == 0) Nil + /** The list of non-empty names of flags with given index idx that are set in the given flag set */ + private def (x: FlagSet) flagString(idx: Int): List[String] = + if ((x.bits & (1L << idx)) == 0) Nil else { def halfString(kind: Int) = - if ((bits & (1L << kind)) != 0) flagName(idx)(kind) else "" + if ((x.bits & (1L << kind)) != 0) flagName(idx)(kind) else "" val termFS = halfString(TERMindex) val typeFS = halfString(TYPEindex) val strs = termFS :: (if (termFS == typeFS) Nil else typeFS :: Nil) strs filter (_.nonEmpty) } - /** The list of non-empty names of flags that are set in this FlagSet */ - def flagStrings(privateWithin: String): Seq[String] = { - var rawStrings = (2 to MaxFlag).flatMap(flagString) - if (!privateWithin.isEmpty && !this.is(Protected)) + /** The list of non-empty names of flags that are set in teh given flag set */ + def (x: FlagSet) flagStrings(privateWithin: String): Seq[String] = { + var rawStrings = (2 to MaxFlag).flatMap(x.flagString(_)) // !!! + if (!privateWithin.isEmpty && !x.is(Protected)) rawStrings = rawStrings :+ "private" - val scopeStr = if (this.is(Local)) "this" else privateWithin + val scopeStr = if (x.is(Local)) "this" else privateWithin if (scopeStr != "") rawStrings.filter(_ != "").map { case "private" => s"private[$scopeStr]" @@ -129,8 +140,8 @@ object Flags { else rawStrings } - /** The string representation of this flag set */ - def flagsString: String = flagStrings("").mkString(" ") + /** The string representation of the given flag set */ + def (x: FlagSet) flagsString: String = x.flagStrings("").mkString(" ") } def termFlagSet(x: Long) = FlagSet(TERMS | x) @@ -148,7 +159,7 @@ object Flags { private val flagName = Array.fill(64, 2)("") - private def isDefinedAsFlag(idx: Int) = flagName(idx) exists (_.nonEmpty) + private def isDefinedAsFlag(idx: Int) = flagName(idx).exists(_.nonEmpty) /** The flag set containing all defined flags of either kind whose bits * lie in the given range @@ -565,11 +576,11 @@ object Flags { /** An inline method or inline argument proxy */ final val InlineOrProxy: FlagSet = Inline | InlineProxy - final val ImplicitOrImplied = Implicit | Implied - final val ImplicitOrImpliedOrGiven = Implicit | Implied | Given - final val ImplicitOrGiven = Implicit | Given + final val ImplicitOrImplied: FlagSet = Implicit | Implied + final val ImplicitOrImpliedOrGiven: FlagSet = Implicit | Implied | Given + final val ImplicitOrGiven: FlagSet = Implicit | Given - final val ImpliedOrGiven = Implied | Given + final val ImpliedOrGiven: FlagSet = Implied | Given final val ImplicitOrImpliedOrGivenTerm = ImplicitOrImpliedOrGiven.toTermFlags @@ -598,7 +609,7 @@ object Flags { final val InlineParam: FlagSet = Inline | Param /** An extension method */ - final val ExtensionMethod = Extension | Method + final val ExtensionMethod: FlagSet = Extension | Method /** An implied method */ final val SyntheticImpliedMethod: FlagSet = Synthetic | Implied | Method diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index c6e1f18b3d5c..2fed3b589d1a 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -187,34 +187,46 @@ object SymDenotations { if (isCurrent(fs)) myFlags else flags /** Has this denotation one of the flags in `fs` set? */ - final def is(fs: FlagSet)(implicit ctx: Context): Boolean = - (if (isCurrent(fs)) myFlags else flags).is(fs) + final def is(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.is(fs) + } /** Has this denotation one of the flags in `fs` set? */ - final def isOneOf(fs: FlagSet)(implicit ctx: Context): Boolean = - (if (isCurrent(fs)) myFlags else flags).isOneOf(fs) + 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) + } /** Has this denotation one of the flags in `fs` set, whereas none of the flags * in `butNot` are set? */ - final def is(fs: FlagSet, butNot: FlagSet)(implicit ctx: Context): Boolean = - (if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags).is(fs, butNot) + final def is(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.is(fs, 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 = - (if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags).isOneOf(fs, butNot) + 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) + } /** Has this denotation all of the flags in `fs` set? */ - final def isAllOf(fs: FlagSet)(implicit ctx: Context): Boolean = - (if (isCurrent(fs)) myFlags else flags).isAllOf(fs) + 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) + } /** 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 = - (if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags).isAllOf(fs, butNot) + 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) + } /** 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/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 7c5e71a10999..fe1135985327 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -70,9 +70,11 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { override protected def recursionLimitExceeded(): Unit = {} protected def PrintableFlags(isType: Boolean): FlagSet = { - if (isType) TypeSourceModifierFlags | Module | Local - else TermSourceModifierFlags | Module | Local - }.toCommonFlags + val fs = + if (isType) TypeSourceModifierFlags | Module | Local // DOTTY problem: cannot merge these two statements + else TermSourceModifierFlags | Module | Local + fs.toCommonFlags + } override def nameString(name: Name): String = if (ctx.settings.YdebugNames.value) name.debugString else NameTransformer.decodeIllegalChars(name.toString) From fa5a986d69c8f6793d8cb7219f1b15c621dbe202 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 19 Jun 2019 18:56:59 +0200 Subject: [PATCH 15/25] Use a delegate for FlagSet extension methods --- compiler/src/dotty/tools/dotc/core/Flags.scala | 2 +- compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala | 2 ++ compiler/src/dotty/tools/dotc/typer/Variances.scala | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 7a639b33184d..670ff81201fa 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -19,7 +19,7 @@ object Flags { type FlagSet = opaques.FlagSet def FlagSet(bits: Long): FlagSet = opaques.FlagSet(bits) - implicit object FlagOps { + delegate FlagOps { def (xs: FlagSet) bits: Long = opaques.toBits(xs) diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index b1d68bf44036..72979effc243 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -17,6 +17,8 @@ import dotty.tools.dotc.util.SourceFile import scala.tasty.reflect.Kernel +import delegate Flags.FlagOps // DOTTY problem: this should not be needed as we should include prefixes of aliases in implicit scopes + 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/typer/Variances.scala b/compiler/src/dotty/tools/dotc/typer/Variances.scala index 014c23c961ee..e18067e9583d 100644 --- a/compiler/src/dotty/tools/dotc/typer/Variances.scala +++ b/compiler/src/dotty/tools/dotc/typer/Variances.scala @@ -3,6 +3,7 @@ package typer import core._ import Types._, Contexts._, Flags._, Symbols._, Annotations._ +import delegate Flags.FlagOps // DOTTY problem: this should not be needed as we should include prefixes of aliases in implicit scopes object Variances { From 855717b522837f89dbc132f481925db11345f669 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 19 Jun 2019 19:07:58 +0200 Subject: [PATCH 16/25] Drop redundant asInstanceOf --- compiler/src/dotty/tools/dotc/core/Flags.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 670ff81201fa..2012e3629db6 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -8,12 +8,12 @@ object Flags { object opaques { /** A FlagSet represents a set of flags. Flags are encoded as follows: - * The first two bits indicate whether a flagset applies to terms, + * The first two bits indicate whether a flag set applies to terms, * to types, or to both. Bits 2..63 are available for properties * and can be doubly used for terms and types. */ opaque type FlagSet = Long - def FlagSet(bits: Long): FlagSet = bits.asInstanceOf // !!! + def FlagSet(bits: Long): FlagSet = bits def toBits(fs: FlagSet): Long = fs } type FlagSet = opaques.FlagSet From bb86f8b10549675a946ef29fd836571dfbc80a79 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 19 Jun 2019 22:48:08 +0200 Subject: [PATCH 17/25] Update comments on what does not work yet --- compiler/src/dotty/tools/dotc/core/Flags.scala | 4 ++++ compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala | 2 +- compiler/src/dotty/tools/dotc/typer/Variances.scala | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 2012e3629db6..eed5886b31aa 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -18,6 +18,10 @@ object Flags { } type FlagSet = opaques.FlagSet def FlagSet(bits: Long): FlagSet = opaques.FlagSet(bits) + // DOTTY problem: would like to replace previous 2 lines with + // export opaques.FlagSet + // but this makes `def FlagSet` in `opaques` ill-typed. + delegate FlagOps { diff --git a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala index 72979effc243..9c5dad9c1c1b 100644 --- a/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala +++ b/compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala @@ -17,7 +17,7 @@ import dotty.tools.dotc.util.SourceFile import scala.tasty.reflect.Kernel -import delegate Flags.FlagOps // DOTTY problem: this should not be needed as we should include prefixes of aliases in implicit scopes +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 { diff --git a/compiler/src/dotty/tools/dotc/typer/Variances.scala b/compiler/src/dotty/tools/dotc/typer/Variances.scala index e18067e9583d..05570bac0bbe 100644 --- a/compiler/src/dotty/tools/dotc/typer/Variances.scala +++ b/compiler/src/dotty/tools/dotc/typer/Variances.scala @@ -3,7 +3,7 @@ package typer import core._ import Types._, Contexts._, Flags._, Symbols._, Annotations._ -import delegate Flags.FlagOps // DOTTY problem: this should not be needed as we should include prefixes of aliases in implicit scopes +import delegate Flags.FlagOps // DOTTY problem: this line can be dropped in 0.17 once #6712 is in bootstrap. object Variances { From 35bc96aa8a0b38a5d7b658aa3dfc1c5e6236f6f6 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 20 Jun 2019 18:57:37 +0200 Subject: [PATCH 18/25] update TODO --- compiler/src/dotty/tools/dotc/core/Flags.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index eed5886b31aa..799691f1930f 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -18,10 +18,9 @@ object Flags { } type FlagSet = opaques.FlagSet def FlagSet(bits: Long): FlagSet = opaques.FlagSet(bits) - // DOTTY problem: would like to replace previous 2 lines with + // DOTTY TODO: replace previous 2 lines with // export opaques.FlagSet - // but this makes `def FlagSet` in `opaques` ill-typed. - + // once 0.17 is released and #6721 is in the bootstrap delegate FlagOps { From abee5488b6ebe1c6e893590e69372416fdc8efda Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 20 Jun 2019 21:54:02 +0200 Subject: [PATCH 19/25] Make `is` type safe This is achieved by creating a new opaque type `Flag` that represents a single flag. --- .../backend/jvm/DottyBackendInterface.scala | 2 +- .../src/dotty/tools/dotc/ast/Desugar.scala | 4 +- compiler/src/dotty/tools/dotc/ast/untpd.scala | 8 +- .../src/dotty/tools/dotc/core/Flags.scala | 279 ++++++++++-------- .../tools/dotc/core/SymDenotations.scala | 16 +- .../tools/dotc/parsing/JavaParsers.scala | 2 +- .../src/dotty/tools/dotc/typer/Inliner.scala | 6 +- 7 files changed, 167 insertions(+), 150 deletions(-) diff --git a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index acc9c4667a49..a9a76fc68644 100644 --- a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -659,7 +659,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma def isExpanded: Boolean = sym.name.is(ExpandedName) def isAnonymousFunction: Boolean = toDenot(sym).isAnonymousFunction def isMethod: Boolean = sym.is(Flags.Method) - def isPublic: Boolean = !sym.flags.is(Flags.Private | Flags.Protected) + def isPublic: Boolean = !sym.flags.isOneOf(Flags.Private | Flags.Protected) def isSynthetic: Boolean = sym.is(Flags.Synthetic) def isPackageClass: Boolean = sym.is(Flags.PackageClass) def isModuleClass: Boolean = sym.is(Flags.ModuleClass) diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 0d18f37c425f..94d052c1be0e 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -1016,9 +1016,9 @@ object desugar { case tree: MemberDef => var tested: MemberDef = tree def fail(msg: String) = ctx.error(msg, tree.sourcePos) - def checkApplicable(flag: FlagSet, test: MemberDefTest): Unit = + def checkApplicable(flag: Flag, test: MemberDefTest): Unit = if (tested.mods.is(flag) && !test.applyOrElse(tree, (md: MemberDef) => false)) { - fail(i"modifier `$flag` is not allowed for this definition") + fail(i"modifier `${flag.flagsString}` is not allowed for this definition") tested = tested.withMods(tested.mods.withoutFlags(flag)) } checkApplicable(Opaque, legalOpaque) diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index d55240d26bdc..865b2e860284 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -183,8 +183,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { annotations: List[Tree] = Nil, mods: List[Mod] = Nil) { - def is(fs: FlagSet): Boolean = flags.is(fs) - def is(fs: FlagSet, butNot: FlagSet): Boolean = flags.is(fs, butNot = butNot) + def is(flag: Flag): Boolean = flags.is(flag) + def is(flag: Flag, butNot: FlagSet): Boolean = flags.is(flag, butNot = butNot) def isOneOf(fs: FlagSet): Boolean = flags.isOneOf(fs) def isOneOf(fs: FlagSet, butNot: FlagSet): Boolean = flags.isOneOf(fs, butNot = butNot) def isAllOf(fc: FlagSet): Boolean = flags.isAllOf(fc) @@ -201,8 +201,8 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { else copy(flags = flags) def withoutFlags(flags: FlagSet): Modifiers = - if (this.is(flags)) - Modifiers(this.flags &~ flags, this.privateWithin, this.annotations, this.mods.filterNot(_.flags.is(flags))) + if (this.isOneOf(flags)) + Modifiers(this.flags &~ flags, this.privateWithin, this.annotations, this.mods.filterNot(_.flags.isOneOf(flags))) else this def withAddedMod(mod: Mod): Modifiers = diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 799691f1930f..a5a4ee2a7477 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -15,6 +15,10 @@ object Flags { opaque type FlagSet = Long def FlagSet(bits: Long): FlagSet = bits def toBits(fs: FlagSet): Long = fs + + /** A flag set consisting of a single flag */ + 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) @@ -22,63 +26,70 @@ object Flags { // export opaques.FlagSet // once 0.17 is released and #6721 is in the bootstrap + type Flag = opaques.Flag + delegate FlagOps { - def (xs: FlagSet) bits: Long = opaques.toBits(xs) + def (x: FlagSet) bits: Long = opaques.toBits(x) /** The union of the given flag sets. * Combining two FlagSets with `|` will give a FlagSet * that has the intersection of the applicability to terms/types * of the two flag sets. It is checked that the intersection is not empty. */ - def (x: FlagSet) | (that: FlagSet): FlagSet = - if (x.bits == 0) that - else if (that.bits == 0) x + def (x: FlagSet) | (y: FlagSet): FlagSet = + if (x.bits == 0) y + else if (y.bits == 0) x else { - val tbits = x.bits & that.bits & KINDFLAGS + val tbits = x.bits & y.bits & KINDFLAGS if (tbits == 0) - assert(false, s"illegal flagset combination: $x and $that") - FlagSet(tbits | ((x.bits | that.bits) & ~KINDFLAGS)) + assert(false, s"illegal flagset combination: $x and $y") + FlagSet(tbits | ((x.bits | y.bits) & ~KINDFLAGS)) } /** The intersection of the given flag sets */ - def (x: FlagSet) & (that: FlagSet): FlagSet = FlagSet(x.bits & that.bits) + def (x: FlagSet) & (y: FlagSet): FlagSet = FlagSet(x.bits & y.bits) /** The intersection of a flag set with the complement of another flag set */ - def (x: FlagSet) &~ (that: FlagSet): FlagSet = { + def (x: FlagSet) &~ (y: FlagSet): FlagSet = { val tbits = x.bits & KINDFLAGS - if ((tbits & that.bits) == 0) x - else FlagSet(tbits | ((x.bits & ~that.bits) & ~KINDFLAGS)) + if ((tbits & y.bits) == 0) x + else FlagSet(tbits | ((x.bits & ~y.bits) & ~KINDFLAGS)) } - def (x: FlagSet) ^ (that: FlagSet) = - FlagSet((x.bits | that.bits) & KINDFLAGS | (x.bits ^ that.bits) & ~KINDFLAGS) + def (x: FlagSet) ^ (y: FlagSet) = + FlagSet((x.bits | y.bits) & KINDFLAGS | (x.bits ^ y.bits) & ~KINDFLAGS) - /** Does a given flag set have a non-empty intersection with another flag set? + /** Does the given flag set contain the given flag? * This means that both the kind flags and the carrier bits have non-empty intersection. */ - def (x: FlagSet) is(flags: FlagSet): Boolean = { - assert(flags.numFlags == 1) - val fs = x.bits & flags.bits + def (x: FlagSet) is (flag: Flag): Boolean = { + val fs = x.bits & flag.bits (fs & KINDFLAGS) != 0 && (fs & ~KINDFLAGS) != 0 } - /** Does a given flag set have a non-empty intersection with another flag set, - * and at the same time contain none of the flags in the `butNot` set? - */ - def (x: FlagSet) is(flags: FlagSet, butNot: FlagSet): Boolean = x.is(flags) && !x.isOneOf(butNot) + /** Does the given flag set contain the given flag + * and at the same time contain none of the flags in the `butNot` set? + */ + def (x: FlagSet) is (flag: Flag, butNot: FlagSet): Boolean = x.is(flag) && !x.isOneOf(butNot) - def (x: FlagSet) isOneOf(flags: FlagSet): Boolean = { + /** Does the given flag set have a non-empty intersection with another flag set? + * This means that both the kind flags and the carrier bits have non-empty intersection. + */ + def (x: FlagSet) isOneOf (flags: FlagSet): Boolean = { val fs = x.bits & flags.bits (fs & KINDFLAGS) != 0 && (fs & ~KINDFLAGS) != 0 } - def (x: FlagSet) isOneOf(flags: FlagSet, butNot: FlagSet): Boolean = x.isOneOf(flags) && !x.isOneOf(butNot) + /** Does the given flag set have a non-empty intersection with another flag set, + * and at the same time contain none of the flags in the `butNot` set? + */ + def (x: FlagSet) isOneOf (flags: FlagSet, butNot: FlagSet): Boolean = x.isOneOf(flags) && !x.isOneOf(butNot) /** Does a given flag set have all of the flags of another flag set? * Pre: The intersection of the term/type flags of both sets must be non-empty. */ - def (x: FlagSet) isAllOf(flags: FlagSet): Boolean = { + def (x: FlagSet) isAllOf (flags: FlagSet): Boolean = { val fs = x.bits & flags.bits ((fs & KINDFLAGS) != 0 || flags.bits == 0) && (fs >>> TYPESHIFT) == (flags.bits >>> TYPESHIFT) @@ -88,12 +99,12 @@ object Flags { * and at the same time contain none of the flags in the `butNot` set? * Pre: The intersection of the term/type flags of both sets must be non-empty. */ - def (x: FlagSet) isAllOf(flags: FlagSet, butNot: FlagSet): Boolean = x.isAllOf(flags) && !x.isOneOf(butNot) + def (x: FlagSet) isAllOf (flags: FlagSet, butNot: FlagSet): Boolean = x.isAllOf(flags) && !x.isOneOf(butNot) def (x: FlagSet) isEmpty: Boolean = (x.bits & ~KINDFLAGS) == 0 /** Is a given flag set a subset of another flag set? */ - def (x: FlagSet) <= (that: FlagSet): Boolean = (x.bits & that.bits) == x.bits + def (x: FlagSet) <= (y: FlagSet): Boolean = (x.bits & y.bits) == x.bits /** Does the given flag set apply to terms? */ def (x: FlagSet) isTermFlags: Boolean = (x.bits & TERMS) != 0 @@ -110,6 +121,10 @@ object Flags { /** The given flag set with all flags transposed to be common flags */ def (x: FlagSet) toCommonFlags: FlagSet = if (x.bits == 0) x else FlagSet(x.bits | KINDFLAGS) + def (x: Flag) toTypeFlag: Flag = if (x.bits == 0) x else opaques.Flag(x.bits & ~KINDFLAGS | TYPES) + def (x: Flag) toTermFlag: Flag = if (x.bits == 0) x else opaques.Flag(x.bits & ~KINDFLAGS | TERMS) + def (x: Flag) toCommonFlag: Flag = if (x.bits == 0) x else opaques.Flag(x.bits & ~KINDFLAGS | KINDFLAGS) + /** The number of non-kind flags in the given flag set */ def (x: FlagSet) numFlags: Int = java.lang.Long.bitCount(x.bits & ~KINDFLAGS) @@ -130,7 +145,7 @@ object Flags { /** The list of non-empty names of flags that are set in teh given flag set */ def (x: FlagSet) flagStrings(privateWithin: String): Seq[String] = { - var rawStrings = (2 to MaxFlag).flatMap(x.flagString(_)) // !!! + var rawStrings = (2 to MaxFlag).flatMap(x.flagString(_)) // DOTTY problem: cannot drop with (_) if (!privateWithin.isEmpty && !x.is(Protected)) rawStrings = rawStrings :+ "private" val scopeStr = if (x.is(Local)) "this" else privateWithin @@ -172,25 +187,28 @@ object Flags { if (isDefinedAsFlag(idx)) bits | (1L << idx) else bits)) /** The flag with given index between 2 and 63 which applies to terms. - * Installs given name as the name of the flag. */ - private def termFlag(index: Int, name: String): FlagSet = { + * Installs given name as the name of the flag. + */ + private def termFlag(index: Int, name: String): Flag = { flagName(index)(TERMindex) = name - FlagSet(TERMS | (1L << index)) + opaques.Flag(TERMS | (1L << index)) } - /** The flag with given index between 2 and 63 which applies to types. - * Installs given name as the name of the flag. */ - private def typeFlag(index: Int, name: String): FlagSet = { + /** The flag with given index between 2 and 63 which applies to types. + * Installs given name as the name of the flag. + */ + private def typeFlag(index: Int, name: String): Flag = { flagName(index)(TYPEindex) = name - FlagSet(TYPES | (1L << index)) + opaques.Flag(TYPES | (1L << index)) } /** The flag with given index between 2 and 63 which applies to both terms and types - * Installs given name as the name of the flag. */ - private def commonFlag(index: Int, name: String): FlagSet = { + * Installs given name as the name of the flag. + */ + private def commonFlag(index: Int, name: String): Flag = { flagName(index)(TERMindex) = name flagName(index)(TYPEindex) = name - FlagSet(TERMS | TYPES | (1L << index)) + opaques.Flag(KINDFLAGS | (1L << index)) } /** The union of all flags in given flag set */ @@ -212,139 +230,137 @@ object Flags { // Available flags: /** Labeled with `private` modifier */ - final val Private: FlagSet = commonFlag(2, "private") - final val PrivateTerm: FlagSet = Private.toTermFlags - final val PrivateType: FlagSet = Private.toTypeFlags + final val Private: Flag = commonFlag(2, "private") + final val PrivateTerm: Flag = Private.toTermFlag + final val PrivateType: Flag = Private.toTypeFlag /** Labeled with `protected` modifier */ - final val Protected: FlagSet = commonFlag(3, "protected") + final val Protected: Flag = commonFlag(3, "protected") /** Labeled with `override` modifier */ - final val Override: FlagSet = commonFlag(4, "override") + final val Override: Flag = commonFlag(4, "override") /** A declared, but not defined member */ - final val Deferred: FlagSet = commonFlag(5, "") - final val DeferredTerm: FlagSet = Deferred.toTermFlags - final val DeferredType: FlagSet = Deferred.toTypeFlags + final val Deferred: Flag = commonFlag(5, "") + final val DeferredTerm: Flag = Deferred.toTermFlag + final val DeferredType: Flag = Deferred.toTypeFlag /** Labeled with `final` modifier */ - final val Final: FlagSet = commonFlag(6, "final") + final val Final: Flag = commonFlag(6, "final") /** A method symbol. */ - final val Method: FlagSet = termFlag(7, "") - final val HigherKinded: FlagSet = typeFlag(7, "") + final val Method: Flag = termFlag(7, "") + final val HigherKinded: Flag = typeFlag(7, "") /** A (term or type) parameter to a class or method */ - final val Param: FlagSet = commonFlag(8, "") - final val TermParam: FlagSet = Param.toTermFlags - final val TypeParam: FlagSet = Param.toTypeFlags + final val Param: Flag = commonFlag(8, "") + final val TermParam: Flag = Param.toTermFlag + final val TypeParam: Flag = Param.toTypeFlag /** Labeled with `implicit` modifier (implicit value) */ - final val Implicit: FlagSet = commonFlag(9, "implicit") - final val ImplicitTerm: FlagSet = Implicit.toTermFlags + final val Implicit: Flag = commonFlag(9, "implicit") + final val ImplicitTerm: Flag = Implicit.toTermFlag /** Labeled with `lazy` (a lazy val). */ - final val Lazy: FlagSet = termFlag(10, "lazy") + final val Lazy: Flag = termFlag(10, "lazy") /** A trait */ - final val Trait: FlagSet = typeFlag(10, "") + final val Trait: Flag = typeFlag(10, "") - final val LazyOrTrait: FlagSet = Lazy.toCommonFlags + final val LazyOrTrait: Flag = Lazy.toCommonFlag /** A value or variable accessor (getter or setter) */ - final val Accessor: FlagSet = termFlag(11, "") + final val Accessor: Flag = termFlag(11, "") /** Labeled with `sealed` modifier (sealed class) */ - final val Sealed: FlagSet = typeFlag(11, "sealed") + final val Sealed: Flag = typeFlag(11, "sealed") - final val AccessorOrSealed: FlagSet = Accessor.toCommonFlags + final val AccessorOrSealed: Flag = Accessor.toCommonFlag /** A mutable var */ - final val Mutable: FlagSet = termFlag(12, "mutable") + final val Mutable: Flag = termFlag(12, "mutable") /** An opaque type or a class containing one */ - final val Opaque: FlagSet = typeFlag(12, "opaque") + final val Opaque: Flag = typeFlag(12, "opaque") - final val MutableOrOpaque: FlagSet = Mutable.toCommonFlags + final val MutableOrOpaque: Flag = Mutable.toCommonFlag /** Symbol is local to current class (i.e. private[this] or protected[this] * pre: Private or Protected are also set */ - final val Local: FlagSet = commonFlag(13, "") + final val Local: Flag = commonFlag(13, "") /** A field generated for a primary constructor parameter (no matter if it's a 'val' or not), * or an accessor of such a field. */ - final val ParamAccessor: FlagSet = termFlag(14, "") + final val ParamAccessor: Flag = termFlag(14, "") /** A value or class implementing a module */ - final val Module: FlagSet = commonFlag(15, "module") - final val ModuleVal: FlagSet = Module.toTermFlags - final val ModuleClass: FlagSet = Module.toTypeFlags + final val Module: Flag = commonFlag(15, "module") + final val ModuleVal: Flag = Module.toTermFlag + final val ModuleClass: Flag = Module.toTypeFlag /** A value or class representing a package */ - final val Package: FlagSet = commonFlag(16, "") - final val PackageVal: FlagSet = Package.toTermFlags - final val PackageClass: FlagSet = Package.toTypeFlags + final val Package: Flag = commonFlag(16, "") + final val PackageVal: Flag = Package.toTermFlag + final val PackageClass: Flag = Package.toTypeFlag /** A case class or its companion object * Note: Case is also used to indicate that a symbol is bound by a pattern. */ - final val Case: FlagSet = commonFlag(17, "case") - final val CaseClass: FlagSet = Case.toTypeFlags - final val CaseVal: FlagSet = Case.toTermFlags + final val Case: Flag = commonFlag(17, "case") + final val CaseClass: Flag = Case.toTypeFlag + final val CaseVal: Flag = Case.toTermFlag /** A compiler-generated symbol, which is visible for type-checking * (compare with artifact) */ - final val Synthetic: FlagSet = commonFlag(18, "") + final val Synthetic: Flag = commonFlag(18, "") /** Labelled with `inline` modifier */ - final val Inline: FlagSet = commonFlag(19, "inline") + final val Inline: Flag = commonFlag(19, "inline") /** A covariant type variable / an outer accessor */ - final val CovariantOrOuter: FlagSet = commonFlag(20, "") - final val Covariant: FlagSet = typeFlag(20, "") - final val OuterAccessor: FlagSet = termFlag(20, "") + final val CovariantOrOuter: Flag = commonFlag(20, "") + final val Covariant: Flag = typeFlag(20, "") + final val OuterAccessor: Flag = termFlag(20, "") /** A contravariant type variable / the label of a labeled block */ - final val ContravariantOrLabel: FlagSet = commonFlag(21, "") - final val Contravariant: FlagSet = typeFlag(21, "") - final val Label: FlagSet = termFlag(21, "