-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Error-specific Diagnostics subclasses #92
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package dotty.tools.dotc.reporting | ||
|
||
class Severity(val level: Int) extends AnyVal { | ||
import Severity._ | ||
|
||
override def toString = this match { | ||
case VerboseINFO => "VerboseINFO" | ||
case INFO => "INFO" | ||
case DeprecationWARNING => "DeprecationWARNING" | ||
case UncheckedWARNING => "UncheckedWARNING" | ||
case FeatureWARNING => "FeatureWARNING" | ||
case WARNING => "WARNING" | ||
case ERROR => "ERROR" | ||
} | ||
} | ||
|
||
object Severity { | ||
final val VerboseINFO = new Severity(0) | ||
final val INFO = new Severity(1) | ||
final val DeprecationWARNING = new Severity(2) | ||
final val UncheckedWARNING = new Severity(3) | ||
final val FeatureWARNING = new Severity(4) | ||
final val WARNING = new Severity(5) | ||
final val ERROR = new Severity(6) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package dotty.tools.dotc | ||
|
||
import core.Contexts._ | ||
import util.SourcePosition | ||
import reporting.Severity._ | ||
|
||
package object reporting { | ||
|
||
class Diagnostic(msgFn: => String, val pos: SourcePosition, val severity: Severity, base: ContextBase) extends Exception { | ||
private var myMsg: String = null | ||
private var myIsSuppressed: Boolean = false | ||
def msg: String = { | ||
if (myMsg == null) | ||
try myMsg = msgFn | ||
catch { | ||
case ex: SuppressedMessage => | ||
myIsSuppressed = true | ||
val saved = base.suppressNonSensicalErrors | ||
base.suppressNonSensicalErrors = false | ||
try myMsg = msgFn | ||
finally base.suppressNonSensicalErrors = saved | ||
} | ||
myMsg | ||
} | ||
def isSuppressed = { msg; myIsSuppressed } | ||
override def toString = s"$severity at $pos: $msg" | ||
override def getMessage() = msg | ||
|
||
def promotedSeverity(implicit ctx: Context): Severity = | ||
if (isConditionalWarning(severity) && enablingOption(severity).value) WARNING | ||
else severity | ||
} | ||
|
||
def Diagnostic(msgFn: => String, pos: SourcePosition, severity: Severity)(implicit ctx: Context) = | ||
new Diagnostic(msgFn, pos, severity, ctx.base) | ||
|
||
def isConditionalWarning(s: Severity) = | ||
DeprecationWARNING.level <= s.level && s.level <= FeatureWARNING.level | ||
|
||
val conditionalWarnings = List(DeprecationWARNING, UncheckedWARNING, FeatureWARNING) | ||
|
||
private[reporting] def enablingOption(warning: Severity)(implicit ctx: Context) = warning match { | ||
case DeprecationWARNING => ctx.settings.deprecation | ||
case UncheckedWARNING => ctx.settings.unchecked | ||
case FeatureWARNING => ctx.settings.feature | ||
} | ||
|
||
class SuppressedMessage extends Exception | ||
|
||
trait CompilerError { self: Diagnostic => } | ||
trait CompilerWarning { self: Diagnostic => } | ||
trait CompilerInfo { self: Diagnostic => | ||
def isVerbose: Boolean | ||
} | ||
|
||
trait ParserDiagnostic { self: Diagnostic => } | ||
trait TyperDiagnostic { self: Diagnostic => } | ||
|
||
class ParserError(msgFn: => String, pos: SourcePosition, base: ContextBase) | ||
extends Diagnostic(msgFn, pos, ERROR, base) with CompilerError with ParserDiagnostic | ||
|
||
class ParserWarning(msgFn: => String, pos: SourcePosition, base: ContextBase) | ||
extends Diagnostic(msgFn, pos, WARNING, base) with CompilerWarning with ParserDiagnostic | ||
|
||
class ParserInfo(msgFn: => String, val isVerbose: Boolean, pos: SourcePosition, base: ContextBase) | ||
extends Diagnostic(msgFn, pos, if (isVerbose) VerboseINFO else INFO, base) with CompilerInfo with ParserDiagnostic | ||
|
||
class TyperError(msgFn: => String, pos: SourcePosition, base: ContextBase) | ||
extends Diagnostic(msgFn, pos, ERROR, base) with CompilerError with TyperDiagnostic | ||
|
||
class TyperWarning(msgFn: => String, pos: SourcePosition, base: ContextBase) | ||
extends Diagnostic(msgFn, pos, WARNING, base) with CompilerWarning with TyperDiagnostic | ||
|
||
class TyperInfo(msgFn: => String, val isVerbose: Boolean, pos: SourcePosition, base: ContextBase) | ||
extends Diagnostic(msgFn, pos, if (isVerbose) VerboseINFO else INFO, base) with CompilerInfo with TyperDiagnostic | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package dotty.tools.dotc | ||
package reporting | ||
package parser | ||
|
||
import core.Contexts._ | ||
import util.SourcePosition | ||
import reporting.Severity._ | ||
|
||
/** all parser error classes */ | ||
object errors { | ||
|
||
class ImplicitToplevelClass private[errors] (pos: SourcePosition, base: ContextBase) extends | ||
ParserError("implicit classes may not be toplevel", pos, base) | ||
|
||
def ImplicitToplevelClass(pos: SourcePosition)(implicit ctx: Context) = | ||
new ImplicitToplevelClass(pos, ctx.base) | ||
|
||
class ImplicitCaseClass private[errors] (pos: SourcePosition, base: ContextBase) extends | ||
ParserError("implicit classes may not be case classes", pos, base) | ||
|
||
def ImplicitCaseClass(pos: SourcePosition)(implicit ctx: Context) = | ||
new ImplicitCaseClass(pos, ctx.base) | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dotty.tools.dotc | ||
package reporting | ||
package typer | ||
|
||
import core.Contexts._ | ||
import core.Types._ | ||
import util.SourcePosition | ||
import reporting.Severity._ | ||
import dotty.tools.dotc.typer.ErrorReporting.InfoString | ||
|
||
/** all typer error classes */ | ||
object errors { | ||
|
||
class NotStableError private[errors] (msgFn: => String, pos: SourcePosition, base: ContextBase) | ||
extends TyperError(msgFn, pos, base) | ||
|
||
def NotStableError(tp: Type, pos: SourcePosition)(implicit ctx: Context) = | ||
new NotStableError(i"$tp is not stable", pos, ctx.base) | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some teams people make a decision to treat warning as errors. It would be good to have a way to configure which types of diagnostics get which level of Severity.
IMHO there should be way to increase severity, but decreasing should be forbidden.