Skip to content
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

sem, pragmas: fix fatal pragma #1386

Merged
merged 6 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions compiler/ast/ast_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,6 @@ type
adSemAlignRequiresPowerOfTwo,
adSemNoReturnHasReturn,
adSemMisplacedDeprecation,
adSemFatalError,
adSemNoUnionForJs,
adSemBitsizeRequiresPositive,
adSemExperimentalRequiresToplevel,
Expand Down Expand Up @@ -1421,7 +1420,7 @@ type
externName*: string
of adSemPragmaRecursiveDependency:
userPragma*: PSym
of adSemCustomUserError:
of adSemCustomUserError, adSemFatalError:
errmsg*: string
of adSemImplicitPragmaError:
implicitPragma*: PSym
Expand Down
8 changes: 7 additions & 1 deletion compiler/front/cli_reporter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3211,7 +3211,6 @@ func astDiagToLegacyReport(conf: ConfigRef, diag: PAstDiag): Report {.inline.} =
adSemAlignRequiresPowerOfTwo,
adSemNoReturnHasReturn,
adSemMisplacedDeprecation,
adSemFatalError,
adSemNoUnionForJs,
adSemBitsizeRequiresPositive,
adSemExperimentalRequiresToplevel,
Expand Down Expand Up @@ -3428,6 +3427,13 @@ func astDiagToLegacyReport(conf: ConfigRef, diag: PAstDiag): Report {.inline.} =
kind: rsemPragmaRecursiveDependency,
sym: diag.userPragma,
ast: diag.wrongNode)
of adSemFatalError:
zerbina marked this conversation as resolved.
Show resolved Hide resolved
semRep = SemReport(
location: some diag.location,
reportInst: diag.instLoc.toReportLineInfo,
kind: rsemFatalError,
str: diag.errmsg,
ast: diag.wrongNode)
of adSemCustomUserError:
semRep = SemReport(
location: some diag.location,
Expand Down
5 changes: 3 additions & 2 deletions compiler/front/msgs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ from compiler/ast/reports_base_sem import ReportContext, ReportContextKind

# when you have data where it belongs, it's easy to see this stuff... should
# `msgs` really depend upon `SemReport`?
from compiler/ast/reports_sem import SemReport
from compiler/ast/reports_sem import SemReport, severity

export InstantiationInfo
export TErrorHandling
Expand Down Expand Up @@ -294,7 +294,8 @@ proc errorActions(
eh: TErrorHandling
): tuple[action: TErrorHandling, withTrace: bool] =
result = (doNothing, false)
if conf.isCompilerFatal(report):
if conf.isCompilerFatal(report) or
(report.category == repSem and report.semReport.severity == rsevFatal):
zerbina marked this conversation as resolved.
Show resolved Hide resolved
# Fatal message such as ICE (internal compiler), errFatal,
result = (doAbort, true)
elif conf.isCodeError(report):
Expand Down
7 changes: 6 additions & 1 deletion compiler/sem/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,12 @@ proc applyStmtPragma(c: PContext, owner: PSym, it: PNode, k: TSpecialWord): PNod
result = c.config.newError(
it, PAstDiag(kind: adSemCustomUserError, errmsg: s.strVal))
of wFatal:
result = c.config.newError(it, PAstDiag(kind: adSemFatalError))
let (s, err) = strLitToStrOrErr(c, it)
result =
if err.isNil:
c.config.newError(it, PAstDiag(kind: adSemFatalError, errmsg: s))
else:
err
of wDefine:
result = processDefine(c, it)
of wUndef:
Expand Down
4 changes: 4 additions & 0 deletions tests/pragmas/tfatal.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
discard """
errormsg: "user message"
"""
{.fatal:"user message".}