Skip to content

Fix #6795: Print flagString #6797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
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
//if (isModuleClassRoot) println(s"moduleClassRoot of $moduleClassRoot found at $readIndex, flags = $flags") // !!! DEBUG
//if (isClassRoot) println(s"classRoot of $classRoot found at $readIndex, flags = ${flags.flagsString}") // !!! DEBUG
//if (isModuleRoot) println(s"moduleRoot of $moduleRoot found at $readIndex, flags = ${flags.flagsString}") // !!! DEBUG
//if (isModuleClassRoot) println(s"moduleClassRoot of $moduleClassRoot found at $readIndex, flags = ${flags.flagsString}") // !!! DEBUG

def completeRoot(denot: ClassDenotation, completer: LazyType): Symbol = {
denot.setFlag(flags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ object messages {
case class AbstractMemberMayNotHaveModifier(sym: Symbol, flag: FlagSet)(
implicit ctx: Context)
extends Message(AbstractMemberMayNotHaveModifierID) {
val msg: String = em"""${hl("abstract")} $sym may not have `$flag' modifier"""
val msg: String = em"""${hl("abstract")} $sym may not have `${flag.flagsString}` modifier"""
val kind: String = "Syntax"
val explanation: String = ""
}
Expand Down Expand Up @@ -1697,7 +1697,7 @@ object messages {
case class ModifiersNotAllowed(flags: FlagSet, printableType: Option[String])(implicit ctx: Context)
extends Message(ModifiersNotAllowedID) {
val kind: String = "Syntax"
val msg: String = em"Modifier(s) $flags not allowed for ${printableType.getOrElse("combination")}"
val msg: String = em"Modifier(s) `${flags.flagsString}` not allowed for ${printableType.getOrElse("combination")}"
val explanation: String = {
val first = "sealed def y: Int = 1"
val second = "sealed lazy class z"
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ object Checking {
def checkNoConflict(flag1: FlagSet, flag2: FlagSet, msg: => String) =
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")
checkNoConflict(flag1, flag2, i"illegal combination of modifiers: `${flag1.flagsString}` and `${flag2.flagsString}` for: $sym")
def checkApplicable(flag: FlagSet, ok: Boolean) =
if (!ok && !sym.is(Synthetic))
fail(i"modifier `$flag` is not allowed for this definition")
fail(i"modifier `${flag.flagsString}` is not allowed for this definition")

if (sym.is(Inline) &&
( sym.is(ParamAccessor) && sym.owner.isClass
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class Namer { typer: Typer =>
case _ => (flags.isTermFlags, flags.toTermFlags, "value")
}
if (!ok)
ctx.error(i"modifier(s) `$flags' incompatible with $kind definition", tree.sourcePos)
ctx.error(i"modifier(s) `${flags.flagsString}` incompatible with $kind definition", tree.sourcePos)
adapted
}

Expand Down
6 changes: 6 additions & 0 deletions tests/neg/i6795-b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- [E083] Syntax Error: tests/neg/i6795-b.scala:1:11 -------------------------------------------------------------------
1 |sealed def y: Int = 1 // error
| ^
| Modifier(s) `sealed` not allowed for method

longer explanation available when compiling with `-explain`
1 change: 1 addition & 0 deletions tests/neg/i6795-b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sealed def y: Int = 1 // error
4 changes: 4 additions & 0 deletions tests/neg/i6795.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Error: tests/neg/i6795.scala:1:13 -----------------------------------------------------------------------------------
1 |erased class Foo // error
|^^^^^^^^^^^^^^^^
|modifier(s) `erased` incompatible with type definition
1 change: 1 addition & 0 deletions tests/neg/i6795.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
erased class Foo // error