aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-02-11 00:11:25 +1100
committerMartin Odersky <odersky@gmail.com>2017-04-04 13:29:38 +0200
commitc245600ed4bfd4af6f2b45e8cae2cf5a63ddeaf0 (patch)
tree8a116622aacd162b206a9dfcacab5db74e3427e8 /compiler/src/dotty/tools/dotc
parent8f3c9a80cd464a962abeede37087ed52a6d9970a (diff)
downloaddotty-c245600ed4bfd4af6f2b45e8cae2cf5a63ddeaf0.tar.gz
dotty-c245600ed4bfd4af6f2b45e8cae2cf5a63ddeaf0.tar.bz2
dotty-c245600ed4bfd4af6f2b45e8cae2cf5a63ddeaf0.zip
More fine-grained distinctions when flags are defined.
Flags like Trait are in fact not always defined when a symbol is created. For symbols loaded from class files, this flag, and some other is defined only once the classfile has been loaded. But this happens in general before the symbol is completed. We model this distinction by separating from the `FromStartFlags` set a new set `AfterLoadFlags` and distinguishing between the two sets in `SymDenotations#is`. Test case is enum-Option.scala. This erroneously complained before that `Enum` was not a trait.
Diffstat (limited to 'compiler/src/dotty/tools/dotc')
-rw-r--r--compiler/src/dotty/tools/dotc/core/Flags.scala17
-rw-r--r--compiler/src/dotty/tools/dotc/core/SymDenotations.scala13
-rw-r--r--compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala2
3 files changed, 23 insertions, 9 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala
index c1267d8a2..29f1078a2 100644
--- a/compiler/src/dotty/tools/dotc/core/Flags.scala
+++ b/compiler/src/dotty/tools/dotc/core/Flags.scala
@@ -450,13 +450,22 @@ object Flags {
/** Flags guaranteed to be set upon symbol creation */
final val FromStartFlags =
- AccessFlags | Module | Package | Deferred | Final | MethodOrHKCommon | Param | ParamAccessor | Scala2ExistentialCommon |
- Mutable.toCommonFlags | InSuperCall | Touched | JavaStatic | CovariantOrOuter | ContravariantOrLabel | ExpandedName | AccessorOrSealed |
- CaseAccessorOrBaseTypeArg | Fresh | Frozen | Erroneous | ImplicitCommon | Permanent | Synthetic |
- Inline | LazyOrTrait | SuperAccessorOrScala2x | SelfNameOrImplClass
+ Module | Package | Deferred | MethodOrHKCommon | Param | ParamAccessor |
+ Scala2ExistentialCommon | Mutable.toCommonFlags | InSuperCall | Touched | JavaStatic |
+ CovariantOrOuter | ContravariantOrLabel | ExpandedName | CaseAccessorOrBaseTypeArg |
+ Fresh | Frozen | Erroneous | ImplicitCommon | Permanent | Synthetic |
+ SuperAccessorOrScala2x | Inline
+
+ /** Flags guaranteed to be set upon symbol creation, or, if symbol is a top-level
+ * class or object, when the class file defining the symbol is loaded (which
+ * is generally before the symbol is completed
+ */
+ final val AfterLoadFlags =
+ FromStartFlags | AccessFlags | Final | AccessorOrSealed | LazyOrTrait | SelfNameOrImplClass
assert(FromStartFlags.isTermFlags && FromStartFlags.isTypeFlags)
// TODO: Should check that FromStartFlags do not change in completion
+ assert(AfterLoadFlags.isTermFlags && AfterLoadFlags.isTypeFlags)
/** A value that's unstable unless complemented with a Stable flag */
final val UnstableValue = Mutable | Method
diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
index db96463e0..27782698d 100644
--- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -163,26 +163,31 @@ object SymDenotations {
setFlag(flags & mask)
}
+ private def isCurrent(fs: FlagSet) =
+ fs <= (
+ if (myInfo.isInstanceOf[SymbolLoader]) FromStartFlags
+ else AfterLoadFlags)
+
/** Has this denotation one of the flags in `fs` set? */
final def is(fs: FlagSet)(implicit ctx: Context) = {
- (if (fs <= FromStartFlags) myFlags else flags) is fs
+ (if (isCurrent(fs)) myFlags else flags) is 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) =
- (if (fs <= FromStartFlags && butNot <= FromStartFlags) myFlags else flags) is (fs, butNot)
+ (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) =
- (if (fs <= FromStartFlags) myFlags else flags) is fs
+ (if (isCurrent(fs)) myFlags else flags) is 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) =
- (if (fs <= FromStartFlags && butNot <= FromStartFlags) myFlags else flags) is (fs, butNot)
+ (if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags) is (fs, butNot)
/** The type info.
* The info is an instance of TypeType iff this is a type denotation
diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
index 57365658e..b0f5f8ab1 100644
--- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
+++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@@ -238,7 +238,7 @@ object messages {
import core.Flags._
val maxDist = 3
val decls = site.decls.flatMap { sym =>
- if (sym.is(Synthetic | PrivateOrLocal) || sym.isConstructor) Nil
+ if (sym.flagsUNSAFE.is(Synthetic | PrivateOrLocal) || sym.isConstructor) Nil
else List((sym.name.show, sym))
}