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: improve and rework semobjconstr #811

Merged
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
19 changes: 0 additions & 19 deletions compiler/ast/ast_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1239,11 +1239,8 @@ type
adSemConstExprExpected
adSemExpectedRangeType
# semobjconstr
adSemFieldAssignmentInvalidNeedSpace
adSemFieldAssignmentInvalid
adSemFieldNotAccessible
adSemFieldOkButAssignedValueInvalid
adSemObjectConstructorIncorrect
adSemObjectRequiresFieldInitNoDefault
adSemExpectedObjectType
adSemExpectedObjectOfType
Expand Down Expand Up @@ -1364,9 +1361,7 @@ type
adSemNamedExprNotAllowed,
adSemNoReturnTypeDeclared,
adSemReturnNotAllowed,
adSemFieldAssignmentInvalidNeedSpace,
adSemFieldAssignmentInvalid,
adSemObjectConstructorIncorrect,
adSemExpectedObjectType,
adSemFoldOverflow,
adSemFoldDivByZero,
Expand Down Expand Up @@ -1514,9 +1509,6 @@ type
wrongFldInfo*: TLineInfo
of adSemFieldNotAccessible:
inaccessible*: PSym
of adSemFieldOkButAssignedValueInvalid:
targetField*: PSym
initVal*: PNode
of adSemObjectRequiresFieldInitNoDefault:
missing*: seq[PSym]
objTyp*: PType
Expand Down Expand Up @@ -1829,17 +1821,6 @@ type
type
TExprFlag* = enum
efLValue, efWantIterator, efInTypeof,
efNeedStatic,
## Use this in contexts where a static value is mandatory
efPreferStatic,
## Use this in contexts where a static value could bring more
## information, but it's not strictly mandatory. This may become
## the default with implicit statics in the future.
efPreferNilResult,
## Use this if you want a certain result (e.g. static value),
## but you don't want to trigger a hard error. For example,
## you may be in position to supply a better error message
## to the user.
efWantStmt, efAllowStmt, efExplain,
efWantValue, efOperand, efNoSemCheck,
efNoEvaluateGeneric, efInCall, efFromHlo, efNoSem2Check,
Expand Down
4 changes: 0 additions & 4 deletions compiler/ast/report_enums.nim
Original file line number Diff line number Diff line change
Expand Up @@ -599,10 +599,6 @@ type
## object field assignment invalid syntax
rsemFieldAssignmentInvalidNeedSpace
## object field assignment invalid syntax, need space after colon
rsemFieldOkButAssignedValueInvalid
## object field assignment, where the field name is ok, but value is not
rsemObjectConstructorIncorrect
## one or more issues encountered with object constructor

# General Type Checks
rsemExpressionHasNoType
Expand Down
1 change: 0 additions & 1 deletion compiler/ast/reports_sem.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## module with semantic analysis legacy reports definitions

import
compiler/ast/[

Check warning on line 4 in compiler/ast/reports_sem.nim

View workflow job for this annotation

GitHub Actions / Build release binaries (macOS)

imported and not used: 'reports_base' [UnusedImport]

Check warning on line 4 in compiler/ast/reports_sem.nim

View workflow job for this annotation

GitHub Actions / Build release binaries (Linux)

imported and not used: 'reports_base' [UnusedImport]

Check warning on line 4 in compiler/ast/reports_sem.nim

View workflow job for this annotation

GitHub Actions / Build docs and release artifacts (Linux)

imported and not used: 'reports_base' [UnusedImport]

Check warning on line 4 in compiler/ast/reports_sem.nim

View workflow job for this annotation

GitHub Actions / Build docs and release artifacts (macOS)

imported and not used: 'reports_base' [UnusedImport]
report_enums,
ast_types,
lineinfos,
Expand Down Expand Up @@ -74,7 +74,6 @@
of rsemExpectedIdentifierInExpr,
rsemExpectedIdentifierWithExprContext,
rsemExpectedOrdinal,
rsemFieldOkButAssignedValueInvalid,
rsemUseOrDiscardExpr,
rsemOnlyDeclaredIdentifierFoundIsError,
rsemCantConvertLiteralToRange:
Expand Down
31 changes: 12 additions & 19 deletions compiler/front/cli_reporter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1526,9 +1526,6 @@ proc reportBody*(conf: ConfigRef, r: SemReport): string =
result = "runtime discriminator must be immutable if branch fields are " &
"initialized, a 'let' binding is required."

of rsemObjectConstructorIncorrect:
result = "Invalid object constructor: '$1'" % r.ast.render

of rsemBorrowTargetNotFound:
result = "no symbol to borrow from found"

Expand Down Expand Up @@ -2154,12 +2151,6 @@ proc reportBody*(conf: ConfigRef, r: SemReport): string =
of rsemFieldNotAccessible:
result = "the field '$1' is not accessible." % r.symstr

of rsemFieldOkButAssignedValueInvalid:
result = "Invalid field assignment '$1'$2" % [
r.wrongNode.render,
tern(r.ast.isNil, "", "; " & r.ast.render)
]

of rsemStrictNotNilResult:
case r.nilIssue:
of Nil:
Expand Down Expand Up @@ -3349,9 +3340,6 @@ func astDiagToLegacyReport(conf: ConfigRef, diag: PAstDiag): Report {.inline.} =
adSemNamedExprNotAllowed,
adSemNoReturnTypeDeclared,
adSemReturnNotAllowed,
adSemFieldAssignmentInvalidNeedSpace,
adSemFieldAssignmentInvalid,
adSemObjectConstructorIncorrect,
adSemExpectedObjectType,
adSemFoldOverflow,
adSemFoldDivByZero,
Expand All @@ -3363,6 +3351,18 @@ func astDiagToLegacyReport(conf: ConfigRef, diag: PAstDiag): Report {.inline.} =
reportInst: diag.instLoc.toReportLineInfo,
kind: kind,
ast: diag.wrongNode)
of adSemFieldAssignmentInvalid:
let n = diag.wrongNode
let kind =
if n.kind == nkInfix and n[0].kind == nkIdent and n[0].ident.s[0] == ':':
rsemFieldAssignmentInvalidNeedSpace
else:
rsemFieldAssignmentInvalid
semRep = SemReport(
location: some diag.location,
reportInst: diag.instLoc.toReportLineInfo,
kind: kind,
ast: n)
of adSemInvalidRangeConversion:
semRep = SemReport(
location: some diag.location,
Expand Down Expand Up @@ -3811,13 +3811,6 @@ func astDiagToLegacyReport(conf: ConfigRef, diag: PAstDiag): Report {.inline.} =
kind: kind,
ast: diag.wrongNode,
sym: diag.inaccessible)
of adSemFieldOkButAssignedValueInvalid:
semRep = SemReport(
location: some diag.location,
reportInst: diag.instLoc.toReportLineInfo,
kind: kind,
ast: diag.initVal,
sym: diag.targetField)
of adSemObjectRequiresFieldInitNoDefault:
semRep = SemReport(
location: some diag.location,
Expand Down
3 changes: 0 additions & 3 deletions compiler/front/msgs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,8 @@ func astDiagToLegacyReportKind*(
of adSemCannotMixTypesAndValuesInTuple: rsemCannotMixTypesAndValuesInTuple
of adSemNoReturnTypeDeclared: rsemNoReturnTypeDeclared
of adSemReturnNotAllowed: rsemReturnNotAllowed
of adSemFieldAssignmentInvalidNeedSpace: rsemFieldAssignmentInvalidNeedSpace
of adSemFieldAssignmentInvalid: rsemFieldAssignmentInvalid
of adSemFieldNotAccessible: rsemFieldNotAccessible
of adSemFieldOkButAssignedValueInvalid: rsemFieldOkButAssignedValueInvalid
of adSemObjectConstructorIncorrect: rsemObjectConstructorIncorrect
of adSemObjectRequiresFieldInitNoDefault: rsemObjectRequiresFieldInitNoDefault
of adSemExpectedObjectType: rsemExpectedObjectType
of adSemExpectedObjectOfType: rsemExpectedObjectType
Expand Down
Loading
Loading