mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-08 21:04:20 +00:00
remove deprecated type pragma syntax, fix bugs that required it (#20199)
* remove deprecated pragma syntax from 0.20.0 closes #4651, closes #16653 with a cheap fix for now due to how early `tfFinal` is set * remove type pragma between name and generics * undo removal, try removing bind expression (0.8.14) * fix test, unremove bind expr * remove again * Update changelog.md Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> * dependencies @ HEAD & weave test dependencies * try fix package ci Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
This commit is contained in:
@@ -20,6 +20,8 @@ when isMainModule:
|
||||
# Leave a note in grammar.txt that it is generated:
|
||||
#| # This file is generated by compiler/parser.nim.
|
||||
import pegs
|
||||
when defined(nimPreviewSlimSystem):
|
||||
import std/syncio
|
||||
var outp = open("doc/grammar.txt", fmWrite)
|
||||
for line in lines("compiler/parser.nim"):
|
||||
if line =~ peg" \s* '#| ' {.*}":
|
||||
@@ -2031,15 +2033,10 @@ proc parseObjectPart(p: var Parser): PNode =
|
||||
result = p.emptyNode
|
||||
|
||||
proc parseObject(p: var Parser): PNode =
|
||||
#| objectDecl = 'object' pragma? ('of' typeDesc)? COMMENT? objectPart
|
||||
#| objectDecl = 'object' ('of' typeDesc)? COMMENT? objectPart
|
||||
result = newNodeP(nkObjectTy, p)
|
||||
getTok(p)
|
||||
if p.tok.tokType == tkCurlyDotLe and p.validInd:
|
||||
# Deprecated since v0.20.0
|
||||
parMessage(p, warnDeprecated, "type pragmas follow the type name; this form of writing pragmas is deprecated")
|
||||
result.add(parsePragma(p))
|
||||
else:
|
||||
result.add(p.emptyNode)
|
||||
result.add(p.emptyNode) # compatibility with old pragma node
|
||||
if p.tok.tokType == tkOf and p.tok.indent < 0:
|
||||
var a = newNodeP(nkOfInherit, p)
|
||||
getTok(p)
|
||||
@@ -2117,39 +2114,24 @@ proc parseTypeClass(p: var Parser): PNode =
|
||||
|
||||
proc parseTypeDef(p: var Parser): PNode =
|
||||
#|
|
||||
#| typeDef = identWithPragmaDot genericParamList? '=' optInd typeDefAux
|
||||
#| indAndComment? / identVisDot genericParamList? pragma '=' optInd typeDefAux
|
||||
#| typeDef = identVisDot genericParamList? pragma '=' optInd typeDefAux
|
||||
#| indAndComment?
|
||||
result = newNodeP(nkTypeDef, p)
|
||||
var identifier = identVis(p, allowDot=true)
|
||||
var identPragma = identifier
|
||||
var pragma: PNode
|
||||
var genericParam: PNode
|
||||
var noPragmaYet = true
|
||||
|
||||
if p.tok.tokType == tkCurlyDotLe:
|
||||
pragma = optPragmas(p)
|
||||
identPragma = newNodeP(nkPragmaExpr, p)
|
||||
identPragma.add(identifier)
|
||||
identPragma.add(pragma)
|
||||
noPragmaYet = false
|
||||
|
||||
if p.tok.tokType == tkBracketLe and p.validInd:
|
||||
if not noPragmaYet:
|
||||
# Deprecated since v0.20.0
|
||||
parMessage(p, warnDeprecated, "pragma before generic parameter list is deprecated")
|
||||
genericParam = parseGenericParamList(p)
|
||||
else:
|
||||
genericParam = p.emptyNode
|
||||
|
||||
if noPragmaYet:
|
||||
pragma = optPragmas(p)
|
||||
if pragma.kind != nkEmpty:
|
||||
identPragma = newNodeP(nkPragmaExpr, p)
|
||||
identPragma.add(identifier)
|
||||
identPragma.add(pragma)
|
||||
elif p.tok.tokType == tkCurlyDotLe:
|
||||
parMessage(p, errGenerated, "pragma already present")
|
||||
pragma = optPragmas(p)
|
||||
if pragma.kind != nkEmpty:
|
||||
identPragma = newNodeP(nkPragmaExpr, p)
|
||||
identPragma.add(identifier)
|
||||
identPragma.add(pragma)
|
||||
|
||||
result.add(identPragma)
|
||||
result.add(genericParam)
|
||||
|
||||
@@ -1327,6 +1327,7 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||
if s.magic == mNone and a[2].kind == nkEmpty:
|
||||
localError(c.config, a.info, errImplOfXexpected % s.name.s)
|
||||
if s.magic != mNone: processMagicType(c, s)
|
||||
let oldFlags = s.typ.flags
|
||||
if a[1].kind != nkEmpty:
|
||||
# We have a generic type declaration here. In generic types,
|
||||
# symbol lookup needs to be done here.
|
||||
@@ -1354,6 +1355,13 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||
if body != nil:
|
||||
body.sym = s
|
||||
body.size = -1 # could not be computed properly
|
||||
if body.kind == tyObject:
|
||||
# add flags applied to generic type to object (nominal) type
|
||||
incl(body.flags, oldFlags)
|
||||
# {.inheritable, final.} is already disallowed, but
|
||||
# object might have been assumed to be final
|
||||
if tfInheritable in oldFlags and tfFinal in body.flags:
|
||||
excl(body.flags, tfFinal)
|
||||
s.typ[^1] = body
|
||||
if tfCovariant in s.typ.flags:
|
||||
checkCovariantParamsUsages(c, s.typ)
|
||||
@@ -1405,6 +1413,13 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||
internalAssert c.config, st.kind in {tyPtr, tyRef}
|
||||
internalAssert c.config, st.lastSon.sym == nil
|
||||
incl st.flags, tfRefsAnonObj
|
||||
let objTy = st.lastSon
|
||||
# add flags for `ref object` etc to underlying `object`
|
||||
incl(objTy.flags, oldFlags)
|
||||
# {.inheritable, final.} is already disallowed, but
|
||||
# object might have been assumed to be final
|
||||
if tfInheritable in oldFlags and tfFinal in objTy.flags:
|
||||
excl(objTy.flags, tfFinal)
|
||||
let obj = newSym(skType, getIdent(c.cache, s.name.s & ":ObjectType"),
|
||||
nextSymId c.idgen, getCurrOwner(c), s.info)
|
||||
let symNode = newSymNode(obj)
|
||||
@@ -1420,8 +1435,8 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||
obj.ast[2] = a[2][0]
|
||||
if sfPure in s.flags:
|
||||
obj.flags.incl sfPure
|
||||
obj.typ = st.lastSon
|
||||
st.lastSon.sym = obj
|
||||
obj.typ = objTy
|
||||
objTy.sym = obj
|
||||
|
||||
proc checkForMetaFields(c: PContext; n: PNode) =
|
||||
proc checkMeta(c: PContext; n: PNode; t: PType) =
|
||||
|
||||
Reference in New Issue
Block a user