mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-02 18:07:59 +00:00
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:
@@ -1075,7 +1075,7 @@ const
|
||||
nfIsRef, nfIsPtr, nfPreventCg, nfLL,
|
||||
nfFromTemplate, nfDefaultRefsParam,
|
||||
nfExecuteOnReload, nfLastRead,
|
||||
nfFirstWrite}
|
||||
nfFirstWrite, nfUseDefaultField}
|
||||
namePos* = 0
|
||||
patternPos* = 1 # empty except for term rewriting macros
|
||||
genericParamsPos* = 2
|
||||
|
||||
@@ -69,8 +69,7 @@ type
|
||||
efWantStmt, efAllowStmt, efDetermineType, efExplain,
|
||||
efWantValue, efOperand, efNoSemCheck,
|
||||
efNoEvaluateGeneric, efInCall, efFromHlo, efNoSem2Check,
|
||||
efNoUndeclared, efIsDotCall, efCannotBeDotCall,
|
||||
efSkipFieldVisibilityCheck
|
||||
efNoUndeclared, efIsDotCall, efCannotBeDotCall
|
||||
# Use this if undeclared identifiers should not raise an error during
|
||||
# overload resolution.
|
||||
efNoDiagnostics
|
||||
|
||||
@@ -76,8 +76,7 @@ proc semConstrField(c: PContext, flags: TExprFlags,
|
||||
let assignment = locateFieldInInitExpr(c, field, initExpr)
|
||||
if assignment != nil:
|
||||
if nfSem in assignment.flags: return assignment[1]
|
||||
if nfUseDefaultField in assignment[1].flags or
|
||||
efSkipFieldVisibilityCheck in flags:
|
||||
if nfUseDefaultField in assignment[1].flags:
|
||||
discard
|
||||
elif not fieldVisible(c, field):
|
||||
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
|
||||
# branches will be reported as an error):
|
||||
var constrCtx = initConstrContext(t, result)
|
||||
let (initResult, defaults) = if nfUseDefaultField in n.flags:
|
||||
semConstructTypeAux(c, constrCtx, flags + {efSkipFieldVisibilityCheck})
|
||||
else:
|
||||
semConstructTypeAux(c, constrCtx, flags)
|
||||
let (initResult, defaults) = semConstructTypeAux(c, constrCtx, flags)
|
||||
result[0].sons.add defaults
|
||||
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:
|
||||
let field = newNodeI(nkExprColonExpr, result.info)
|
||||
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
|
||||
doAssert obj.sym.position == currPosition
|
||||
inc currPosition
|
||||
|
||||
@@ -3,7 +3,7 @@ discard """
|
||||
targets: "c cpp js"
|
||||
"""
|
||||
|
||||
import std/[times, tables]
|
||||
import std/[times, tables, macros]
|
||||
|
||||
type
|
||||
Guess = object
|
||||
@@ -457,5 +457,25 @@ template main {.dirty.} =
|
||||
var d = default(Bar)
|
||||
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()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user