fixes #20740; fixes pre-existing field visibility issues and removes efSkipFieldVisibilityCheck (#20741)
fixes #20740 pre-existing field visibility and refactoring
This commit is contained in:
parent
6b1e353aa1
commit
c4e5dab419
5 changed files with 28 additions and 11 deletions
|
|
@ -1075,7 +1075,7 @@ const
|
||||||
nfIsRef, nfIsPtr, nfPreventCg, nfLL,
|
nfIsRef, nfIsPtr, nfPreventCg, nfLL,
|
||||||
nfFromTemplate, nfDefaultRefsParam,
|
nfFromTemplate, nfDefaultRefsParam,
|
||||||
nfExecuteOnReload, nfLastRead,
|
nfExecuteOnReload, nfLastRead,
|
||||||
nfFirstWrite}
|
nfFirstWrite, nfUseDefaultField}
|
||||||
namePos* = 0
|
namePos* = 0
|
||||||
patternPos* = 1 # empty except for term rewriting macros
|
patternPos* = 1 # empty except for term rewriting macros
|
||||||
genericParamsPos* = 2
|
genericParamsPos* = 2
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,7 @@ type
|
||||||
efWantStmt, efAllowStmt, efDetermineType, efExplain,
|
efWantStmt, efAllowStmt, efDetermineType, efExplain,
|
||||||
efWantValue, efOperand, efNoSemCheck,
|
efWantValue, efOperand, efNoSemCheck,
|
||||||
efNoEvaluateGeneric, efInCall, efFromHlo, efNoSem2Check,
|
efNoEvaluateGeneric, efInCall, efFromHlo, efNoSem2Check,
|
||||||
efNoUndeclared, efIsDotCall, efCannotBeDotCall,
|
efNoUndeclared, efIsDotCall, efCannotBeDotCall
|
||||||
efSkipFieldVisibilityCheck
|
|
||||||
# Use this if undeclared identifiers should not raise an error during
|
# Use this if undeclared identifiers should not raise an error during
|
||||||
# overload resolution.
|
# overload resolution.
|
||||||
efNoDiagnostics
|
efNoDiagnostics
|
||||||
|
|
|
||||||
|
|
@ -76,8 +76,7 @@ proc semConstrField(c: PContext, flags: TExprFlags,
|
||||||
let assignment = locateFieldInInitExpr(c, field, initExpr)
|
let assignment = locateFieldInInitExpr(c, field, initExpr)
|
||||||
if assignment != nil:
|
if assignment != nil:
|
||||||
if nfSem in assignment.flags: return assignment[1]
|
if nfSem in assignment.flags: return assignment[1]
|
||||||
if nfUseDefaultField in assignment[1].flags or
|
if nfUseDefaultField in assignment[1].flags:
|
||||||
efSkipFieldVisibilityCheck in flags:
|
|
||||||
discard
|
discard
|
||||||
elif not fieldVisible(c, field):
|
elif not fieldVisible(c, field):
|
||||||
localError(c.config, initExpr.info,
|
localError(c.config, initExpr.info,
|
||||||
|
|
@ -416,10 +415,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType
|
||||||
# field (if this is a case object, initialized fields in two different
|
# field (if this is a case object, initialized fields in two different
|
||||||
# branches will be reported as an error):
|
# branches will be reported as an error):
|
||||||
var constrCtx = initConstrContext(t, result)
|
var constrCtx = initConstrContext(t, result)
|
||||||
let (initResult, defaults) = if nfUseDefaultField in n.flags:
|
let (initResult, defaults) = semConstructTypeAux(c, constrCtx, flags)
|
||||||
semConstructTypeAux(c, constrCtx, flags + {efSkipFieldVisibilityCheck})
|
|
||||||
else:
|
|
||||||
semConstructTypeAux(c, constrCtx, flags)
|
|
||||||
result[0].sons.add defaults
|
result[0].sons.add defaults
|
||||||
var hasError = false # needed to split error detect/report for better msgs
|
var hasError = false # needed to split error detect/report for better msgs
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1810,7 +1810,9 @@ proc getNullValueAux(t: PType; obj: PNode, result: PNode; conf: ConfigRef; currP
|
||||||
of nkSym:
|
of nkSym:
|
||||||
let field = newNodeI(nkExprColonExpr, result.info)
|
let field = newNodeI(nkExprColonExpr, result.info)
|
||||||
field.add(obj)
|
field.add(obj)
|
||||||
field.add(getNullValue(obj.sym.typ, result.info, conf))
|
let value = getNullValue(obj.sym.typ, result.info, conf)
|
||||||
|
value.flags.incl nfUseDefaultField
|
||||||
|
field.add(value)
|
||||||
result.add field
|
result.add field
|
||||||
doAssert obj.sym.position == currPosition
|
doAssert obj.sym.position == currPosition
|
||||||
inc currPosition
|
inc currPosition
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ discard """
|
||||||
targets: "c cpp js"
|
targets: "c cpp js"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import std/[times, tables]
|
import std/[times, tables, macros]
|
||||||
|
|
||||||
type
|
type
|
||||||
Guess = object
|
Guess = object
|
||||||
|
|
@ -457,5 +457,25 @@ template main {.dirty.} =
|
||||||
var d = default(Bar)
|
var d = default(Bar)
|
||||||
doAssert d.t == 0
|
doAssert d.t == 0
|
||||||
|
|
||||||
|
block: # bug #20740
|
||||||
|
block:
|
||||||
|
proc foo(x: static DateTime = Datetime()) =
|
||||||
|
discard
|
||||||
|
|
||||||
|
foo()
|
||||||
|
|
||||||
|
block:
|
||||||
|
macro foo(x: static DateTime) =
|
||||||
|
discard x
|
||||||
|
|
||||||
|
macro foo2: untyped =
|
||||||
|
var x = DateTime()
|
||||||
|
|
||||||
|
result = quote do:
|
||||||
|
foo(`x`)
|
||||||
|
|
||||||
|
foo2()
|
||||||
|
|
||||||
|
|
||||||
static: main()
|
static: main()
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue