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:
parent
f540fd5cde
commit
86f7f4ffa5
44 changed files with 111 additions and 86 deletions
|
|
@ -30,6 +30,8 @@
|
||||||
|
|
||||||
- The `{.this.}` pragma, deprecated since 0.19, has been removed.
|
- The `{.this.}` pragma, deprecated since 0.19, has been removed.
|
||||||
- `nil` is no longer a valid value for distinct pointer types.
|
- `nil` is no longer a valid value for distinct pointer types.
|
||||||
|
- Removed two type pragma syntaxes deprecated since 0.20, namely
|
||||||
|
`type Foo = object {.final.}`, and `type Foo {.final.} [T] = object`.
|
||||||
|
|
||||||
## Standard library additions and changes
|
## Standard library additions and changes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ when isMainModule:
|
||||||
# Leave a note in grammar.txt that it is generated:
|
# Leave a note in grammar.txt that it is generated:
|
||||||
#| # This file is generated by compiler/parser.nim.
|
#| # This file is generated by compiler/parser.nim.
|
||||||
import pegs
|
import pegs
|
||||||
|
when defined(nimPreviewSlimSystem):
|
||||||
|
import std/syncio
|
||||||
var outp = open("doc/grammar.txt", fmWrite)
|
var outp = open("doc/grammar.txt", fmWrite)
|
||||||
for line in lines("compiler/parser.nim"):
|
for line in lines("compiler/parser.nim"):
|
||||||
if line =~ peg" \s* '#| ' {.*}":
|
if line =~ peg" \s* '#| ' {.*}":
|
||||||
|
|
@ -2031,15 +2033,10 @@ proc parseObjectPart(p: var Parser): PNode =
|
||||||
result = p.emptyNode
|
result = p.emptyNode
|
||||||
|
|
||||||
proc parseObject(p: var Parser): PNode =
|
proc parseObject(p: var Parser): PNode =
|
||||||
#| objectDecl = 'object' pragma? ('of' typeDesc)? COMMENT? objectPart
|
#| objectDecl = 'object' ('of' typeDesc)? COMMENT? objectPart
|
||||||
result = newNodeP(nkObjectTy, p)
|
result = newNodeP(nkObjectTy, p)
|
||||||
getTok(p)
|
getTok(p)
|
||||||
if p.tok.tokType == tkCurlyDotLe and p.validInd:
|
result.add(p.emptyNode) # compatibility with old pragma node
|
||||||
# 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)
|
|
||||||
if p.tok.tokType == tkOf and p.tok.indent < 0:
|
if p.tok.tokType == tkOf and p.tok.indent < 0:
|
||||||
var a = newNodeP(nkOfInherit, p)
|
var a = newNodeP(nkOfInherit, p)
|
||||||
getTok(p)
|
getTok(p)
|
||||||
|
|
@ -2117,39 +2114,24 @@ proc parseTypeClass(p: var Parser): PNode =
|
||||||
|
|
||||||
proc parseTypeDef(p: var Parser): PNode =
|
proc parseTypeDef(p: var Parser): PNode =
|
||||||
#|
|
#|
|
||||||
#| typeDef = identWithPragmaDot genericParamList? '=' optInd typeDefAux
|
#| typeDef = identVisDot genericParamList? pragma '=' optInd typeDefAux
|
||||||
#| indAndComment? / identVisDot genericParamList? pragma '=' optInd typeDefAux
|
|
||||||
#| indAndComment?
|
#| indAndComment?
|
||||||
result = newNodeP(nkTypeDef, p)
|
result = newNodeP(nkTypeDef, p)
|
||||||
var identifier = identVis(p, allowDot=true)
|
var identifier = identVis(p, allowDot=true)
|
||||||
var identPragma = identifier
|
var identPragma = identifier
|
||||||
var pragma: PNode
|
var pragma: PNode
|
||||||
var genericParam: 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 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)
|
genericParam = parseGenericParamList(p)
|
||||||
else:
|
else:
|
||||||
genericParam = p.emptyNode
|
genericParam = p.emptyNode
|
||||||
|
|
||||||
if noPragmaYet:
|
|
||||||
pragma = optPragmas(p)
|
pragma = optPragmas(p)
|
||||||
if pragma.kind != nkEmpty:
|
if pragma.kind != nkEmpty:
|
||||||
identPragma = newNodeP(nkPragmaExpr, p)
|
identPragma = newNodeP(nkPragmaExpr, p)
|
||||||
identPragma.add(identifier)
|
identPragma.add(identifier)
|
||||||
identPragma.add(pragma)
|
identPragma.add(pragma)
|
||||||
elif p.tok.tokType == tkCurlyDotLe:
|
|
||||||
parMessage(p, errGenerated, "pragma already present")
|
|
||||||
|
|
||||||
result.add(identPragma)
|
result.add(identPragma)
|
||||||
result.add(genericParam)
|
result.add(genericParam)
|
||||||
|
|
|
||||||
|
|
@ -1327,6 +1327,7 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||||
if s.magic == mNone and a[2].kind == nkEmpty:
|
if s.magic == mNone and a[2].kind == nkEmpty:
|
||||||
localError(c.config, a.info, errImplOfXexpected % s.name.s)
|
localError(c.config, a.info, errImplOfXexpected % s.name.s)
|
||||||
if s.magic != mNone: processMagicType(c, s)
|
if s.magic != mNone: processMagicType(c, s)
|
||||||
|
let oldFlags = s.typ.flags
|
||||||
if a[1].kind != nkEmpty:
|
if a[1].kind != nkEmpty:
|
||||||
# We have a generic type declaration here. In generic types,
|
# We have a generic type declaration here. In generic types,
|
||||||
# symbol lookup needs to be done here.
|
# symbol lookup needs to be done here.
|
||||||
|
|
@ -1354,6 +1355,13 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||||
if body != nil:
|
if body != nil:
|
||||||
body.sym = s
|
body.sym = s
|
||||||
body.size = -1 # could not be computed properly
|
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
|
s.typ[^1] = body
|
||||||
if tfCovariant in s.typ.flags:
|
if tfCovariant in s.typ.flags:
|
||||||
checkCovariantParamsUsages(c, s.typ)
|
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.kind in {tyPtr, tyRef}
|
||||||
internalAssert c.config, st.lastSon.sym == nil
|
internalAssert c.config, st.lastSon.sym == nil
|
||||||
incl st.flags, tfRefsAnonObj
|
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"),
|
let obj = newSym(skType, getIdent(c.cache, s.name.s & ":ObjectType"),
|
||||||
nextSymId c.idgen, getCurrOwner(c), s.info)
|
nextSymId c.idgen, getCurrOwner(c), s.info)
|
||||||
let symNode = newSymNode(obj)
|
let symNode = newSymNode(obj)
|
||||||
|
|
@ -1420,8 +1435,8 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||||
obj.ast[2] = a[2][0]
|
obj.ast[2] = a[2][0]
|
||||||
if sfPure in s.flags:
|
if sfPure in s.flags:
|
||||||
obj.flags.incl sfPure
|
obj.flags.incl sfPure
|
||||||
obj.typ = st.lastSon
|
obj.typ = objTy
|
||||||
st.lastSon.sym = obj
|
objTy.sym = obj
|
||||||
|
|
||||||
proc checkForMetaFields(c: PContext; n: PNode) =
|
proc checkForMetaFields(c: PContext; n: PNode) =
|
||||||
proc checkMeta(c: PContext; n: PNode; t: PType) =
|
proc checkMeta(c: PContext; n: PNode; t: PType) =
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,7 @@ objectCase = 'case' identWithPragma ':' typeDesc ':'? COMMENT?
|
||||||
| IND{=} objectBranches)
|
| IND{=} objectBranches)
|
||||||
objectPart = IND{>} objectPart^+IND{=} DED
|
objectPart = IND{>} objectPart^+IND{=} DED
|
||||||
/ objectWhen / objectCase / 'nil' / 'discard' / declColonEquals
|
/ objectWhen / objectCase / 'nil' / 'discard' / declColonEquals
|
||||||
objectDecl = 'object' pragma? ('of' typeDesc)? COMMENT? objectPart
|
objectDecl = 'object' ('of' typeDesc)? COMMENT? objectPart
|
||||||
conceptParam = ('var' | 'out')? symbol
|
conceptParam = ('var' | 'out')? symbol
|
||||||
conceptDecl = 'concept' conceptParam ^* ',' (pragma)? ('of' typeDesc ^* ',')?
|
conceptDecl = 'concept' conceptParam ^* ',' (pragma)? ('of' typeDesc ^* ',')?
|
||||||
&IND{>} stmt
|
&IND{>} stmt
|
||||||
|
|
|
||||||
|
|
@ -2893,7 +2893,7 @@ the variable has been initialized and does not rely on syntactic properties:
|
||||||
|
|
||||||
```nim
|
```nim
|
||||||
type
|
type
|
||||||
MyObject = object {.requiresInit.}
|
MyObject {.requiresInit.} = object
|
||||||
|
|
||||||
proc p() =
|
proc p() =
|
||||||
# the following is valid:
|
# the following is valid:
|
||||||
|
|
@ -7775,7 +7775,7 @@ Produces:
|
||||||
|
|
||||||
```nim
|
```nim
|
||||||
type
|
type
|
||||||
VectorIterator {.importcpp: "std::vector<'0>::iterator".} [T] = object
|
VectorIterator[T] {.importcpp: "std::vector<'0>::iterator".} = object
|
||||||
|
|
||||||
var x: VectorIterator[cint]
|
var x: VectorIterator[cint]
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -286,7 +286,7 @@ else:
|
||||||
moSequentiallyConsistent
|
moSequentiallyConsistent
|
||||||
|
|
||||||
type
|
type
|
||||||
# Atomic* {.importcpp: "_Atomic('0)".} [T] = object
|
# Atomic*[T] {.importcpp: "_Atomic('0)".} = object
|
||||||
|
|
||||||
AtomicInt8 {.importc: "_Atomic NI8".} = int8
|
AtomicInt8 {.importc: "_Atomic NI8".} = int8
|
||||||
AtomicInt16 {.importc: "_Atomic NI16".} = int16
|
AtomicInt16 {.importc: "_Atomic NI16".} = int16
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
include "system/inclrtl"
|
include "system/inclrtl"
|
||||||
when defined(nimPreviewSlimSystem):
|
when defined(nimPreviewSlimSystem):
|
||||||
import std/syncio
|
import std/[syncio, assertions]
|
||||||
|
|
||||||
const
|
const
|
||||||
useUnicode = true ## change this to deactivate proper UTF-8 support
|
useUnicode = true ## change this to deactivate proper UTF-8 support
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
# included from testament.nim
|
# included from testament.nim
|
||||||
|
|
||||||
import important_packages
|
import important_packages
|
||||||
import std/strformat
|
import std/[strformat, strutils]
|
||||||
from std/sequtils import filterIt
|
from std/sequtils import filterIt
|
||||||
|
|
||||||
const
|
const
|
||||||
|
|
@ -448,7 +448,10 @@ proc testNimblePackages(r: var TResults; cat: Category; packageFilter: string) =
|
||||||
let describeOutput = tryCommand("git describe --tags --abbrev=0")
|
let describeOutput = tryCommand("git describe --tags --abbrev=0")
|
||||||
discard tryCommand("git checkout $#" % [describeOutput.strip.quoteShell])
|
discard tryCommand("git checkout $#" % [describeOutput.strip.quoteShell])
|
||||||
discard tryCommand("nimble install --depsOnly -y", maxRetries = 3)
|
discard tryCommand("nimble install --depsOnly -y", maxRetries = 3)
|
||||||
discard tryCommand(pkg.cmd, reFailed = reBuildFailed)
|
let cmds = pkg.cmd.split(';')
|
||||||
|
for i in 0 ..< cmds.len - 1:
|
||||||
|
discard tryCommand(cmds[i], maxRetries = 3)
|
||||||
|
discard tryCommand(cmds[^1], reFailed = reBuildFailed)
|
||||||
inc r.passed
|
inc r.passed
|
||||||
r.addResult(test, targetC, "", "", "", reSuccess, allowFailure = pkg.allowFailure)
|
r.addResult(test, targetC, "", "", "", reSuccess, allowFailure = pkg.allowFailure)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -98,18 +98,18 @@ pkg "nicy", "nim c -r src/nicy.nim"
|
||||||
pkg "nigui", "nim c -o:niguii -r src/nigui.nim"
|
pkg "nigui", "nim c -o:niguii -r src/nigui.nim"
|
||||||
pkg "nimcrypto", "nim r --path:. tests/testall.nim" # `--path:.` workaround needed, see D20210308T165435
|
pkg "nimcrypto", "nim r --path:. tests/testall.nim" # `--path:.` workaround needed, see D20210308T165435
|
||||||
pkg "NimData", "nim c -o:nimdataa src/nimdata.nim"
|
pkg "NimData", "nim c -o:nimdataa src/nimdata.nim"
|
||||||
pkg "nimes", "nim c src/nimes.nim"
|
pkg "nimes", "nimble install -y sdl2@#HEAD;nim c src/nimes.nim"
|
||||||
pkg "nimfp", "nim c -o:nfp -r src/fp.nim"
|
pkg "nimfp", "nim c -o:nfp -r src/fp.nim"
|
||||||
pkg "nimgame2", "nim c nimgame2/nimgame.nim"
|
pkg "nimgame2", "nim c nimgame2/nimgame.nim"
|
||||||
# XXX Doesn't work with deprecated 'randomize', will create a PR.
|
# XXX Doesn't work with deprecated 'randomize', will create a PR.
|
||||||
pkg "nimgen", "nim c -o:nimgenn -r src/nimgen/runcfg.nim"
|
pkg "nimgen", "nim c -o:nimgenn -r src/nimgen/runcfg.nim"
|
||||||
pkg "nimlsp"
|
pkg "nimlsp", allowFailure = true # dependency on ast_pattern_matching
|
||||||
pkg "nimly", "nim c -r tests/test_readme_example.nim"
|
pkg "nimly", "nim c -r tests/test_readme_example.nim"
|
||||||
pkg "nimongo", "nimble test_ci", allowFailure = true
|
pkg "nimongo", "nimble test_ci", allowFailure = true
|
||||||
pkg "nimph", "nimble test", "https://github.com/disruptek/nimph", allowFailure = true
|
pkg "nimph", "nimble test", "https://github.com/disruptek/nimph", allowFailure = true
|
||||||
pkg "nimpy", "nim c -r tests/nimfrompy.nim"
|
pkg "nimpy", "nim c -r tests/nimfrompy.nim"
|
||||||
pkg "nimquery"
|
pkg "nimquery"
|
||||||
pkg "nimsl"
|
pkg "nimsl", "nimble install -y variant@#HEAD;nimble test"
|
||||||
pkg "nimsvg"
|
pkg "nimsvg"
|
||||||
pkg "nimterop", "nimble minitest"
|
pkg "nimterop", "nimble minitest"
|
||||||
pkg "nimwc", "nim c nimwc.nim"
|
pkg "nimwc", "nim c nimwc.nim"
|
||||||
|
|
@ -157,7 +157,7 @@ pkg "tiny_sqlite"
|
||||||
pkg "unicodedb", "nim c -d:release -r tests/tests.nim"
|
pkg "unicodedb", "nim c -d:release -r tests/tests.nim"
|
||||||
pkg "unicodeplus", "nim c -d:release -r tests/tests.nim"
|
pkg "unicodeplus", "nim c -d:release -r tests/tests.nim"
|
||||||
pkg "unpack"
|
pkg "unpack"
|
||||||
pkg "weave", "nimble test_gc_arc"
|
pkg "weave", "nimble install -y cligen synthesis;nimble test_gc_arc"
|
||||||
pkg "websocket", "nim c websocket.nim"
|
pkg "websocket", "nim c websocket.nim"
|
||||||
pkg "winim", "nim c winim.nim"
|
pkg "winim", "nim c winim.nim"
|
||||||
pkg "with"
|
pkg "with"
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ block tcopy:
|
||||||
|
|
||||||
block tgenericassign:
|
block tgenericassign:
|
||||||
type
|
type
|
||||||
TAny = object {.pure.}
|
TAny {.pure.} = object
|
||||||
value: pointer
|
value: pointer
|
||||||
rawType: pointer
|
rawType: pointer
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -561,7 +561,7 @@ when isMainModule:
|
||||||
echo "got the ident m"
|
echo "got the ident m"
|
||||||
|
|
||||||
testRecCase:
|
testRecCase:
|
||||||
type Obj[T] = object {.inheritable.}
|
type Obj[T] {.inheritable.} = object
|
||||||
name: string
|
name: string
|
||||||
case isFat: bool
|
case isFat: bool
|
||||||
of true:
|
of true:
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
discard """
|
discard """
|
||||||
errormsg: "ambiguous call"
|
errormsg: "ambiguous call"
|
||||||
file: "tbind2.nim"
|
file: "told_bind_expr.nim"
|
||||||
line: 12
|
line: 13
|
||||||
"""
|
"""
|
||||||
# Test the new ``bind`` keyword for templates
|
|
||||||
|
# Pre-0.9 deprecated bind expression syntax
|
||||||
|
|
||||||
proc p1(x: int8, y: int): int = return x + y
|
proc p1(x: int8, y: int): int = return x + y
|
||||||
proc p1(x: int, y: int8): int = return x - y
|
proc p1(x: int, y: int8): int = return x - y
|
||||||
|
|
@ -29,7 +29,7 @@ template test =
|
||||||
var b = 1
|
var b = 1
|
||||||
say (b += 1; b), (b += 1; b) #2,3
|
say (b += 1; b), (b += 1; b) #2,3
|
||||||
|
|
||||||
type C = object {.byRef.}
|
type C {.byRef.} = object
|
||||||
i: int
|
i: int
|
||||||
|
|
||||||
proc say(a, b: C) =
|
proc say(a, b: C) =
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ type
|
||||||
Features: seq[Feature] # Read-Only
|
Features: seq[Feature] # Read-Only
|
||||||
|
|
||||||
PNode* = ref Node
|
PNode* = ref Node
|
||||||
Node = object {.inheritable.}
|
Node {.inheritable.} = object
|
||||||
attributes*: seq[PAttr]
|
attributes*: seq[PAttr]
|
||||||
childNodes*: seq[PNode]
|
childNodes*: seq[PNode]
|
||||||
FLocalName: string # Read-only
|
FLocalName: string # Read-only
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ type
|
||||||
className* : string
|
className* : string
|
||||||
TClassOfTobj = object of TClassOfTCustomObject
|
TClassOfTobj = object of TClassOfTCustomObject
|
||||||
nil
|
nil
|
||||||
TCustomObject = ref object {.inheritable.}
|
TCustomObject {.inheritable.} = ref object
|
||||||
class* : ptr TClassOfTCustomObject
|
class* : ptr TClassOfTCustomObject
|
||||||
TObj = ref object of TCustomObject
|
TObj = ref object of TCustomObject
|
||||||
data: int
|
data: int
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ template <typename X> class C {
|
||||||
};
|
};
|
||||||
""".}
|
""".}
|
||||||
|
|
||||||
type C{.importcpp, header: "<stdio.h>", nodecl.} [X] = object
|
type C[X] {.importcpp, header: "<stdio.h>", nodecl.} = object
|
||||||
proc mkC[X]: C[X] {.importcpp: "C<'*0>()", constructor, nodecl.}
|
proc mkC[X]: C[X] {.importcpp: "C<'*0>()", constructor, nodecl.}
|
||||||
|
|
||||||
proc foo(): C[int] =
|
proc foo(): C[int] =
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ disabled: "windows" # pending bug #18011
|
||||||
|
|
||||||
# bug #4730
|
# bug #4730
|
||||||
|
|
||||||
type Vector* {.importcpp: "std::vector", header: "<vector>".}[T] = object
|
type Vector*[T] {.importcpp: "std::vector", header: "<vector>".} = object
|
||||||
|
|
||||||
template `[]=`*[T](v: var Vector[T], key: int, val: T) =
|
template `[]=`*[T](v: var Vector[T], key: int, val: T) =
|
||||||
{.emit: [v, "[", key, "] = ", val, ";"].}
|
{.emit: [v, "[", key, "] = ", val, ";"].}
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ struct Vector {
|
||||||
""".}
|
""".}
|
||||||
|
|
||||||
type
|
type
|
||||||
Vector {.importcpp: "Vector".} [T] = object
|
Vector[T] {.importcpp: "Vector".} = object
|
||||||
VectorIterator {.importcpp: "Vector<'0>::Iterator".} [T] = object
|
VectorIterator[T] {.importcpp: "Vector<'0>::Iterator".} = object
|
||||||
|
|
||||||
var x: VectorIterator[void]
|
var x: VectorIterator[void]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ discard """
|
||||||
"""
|
"""
|
||||||
{.push warningAsError[Effect]: on.}
|
{.push warningAsError[Effect]: on.}
|
||||||
type
|
type
|
||||||
TObj = object {.pure, inheritable.}
|
TObj {.pure, inheritable.} = object
|
||||||
TObjB = object of TObj
|
TObjB = object of TObj
|
||||||
a, b, c: string
|
a, b, c: string
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ discard """
|
||||||
"""
|
"""
|
||||||
|
|
||||||
type
|
type
|
||||||
TObj = object {.pure, inheritable.}
|
TObj {.pure, inheritable.} = object
|
||||||
TObjB = object of TObj
|
TObjB = object of TObj
|
||||||
a, b, c: string
|
a, b, c: string
|
||||||
fn: proc (): int {.tags: [].}
|
fn: proc (): int {.tags: [].}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ discard """
|
||||||
"""
|
"""
|
||||||
|
|
||||||
type
|
type
|
||||||
TObj = object {.pure, inheritable.}
|
TObj {.pure, inheritable.} = object
|
||||||
TObjB = object of TObj
|
TObjB = object of TObj
|
||||||
a, b, c: string
|
a, b, c: string
|
||||||
fn: proc (): int {.tags: [ReadIOEffect].}
|
fn: proc (): int {.tags: [ReadIOEffect].}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ tinvalidinout.nim(18, 9) Error: the 'in' modifier can be used only with imported
|
||||||
"""
|
"""
|
||||||
|
|
||||||
type
|
type
|
||||||
Foo {.header: "foo.h", importcpp.} [in T] = object
|
Foo[in T] {.header: "foo.h", importcpp.} = object
|
||||||
|
|
||||||
Bar[out X] = object
|
Bar[out X] = object
|
||||||
x: int
|
x: int
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ doAssert(getCurrentException() == nil)
|
||||||
# raise by pointer and also generic type
|
# raise by pointer and also generic type
|
||||||
|
|
||||||
type
|
type
|
||||||
std_vector {.importcpp"std::vector", header"<vector>".} [T] = object
|
std_vector[T] {.importcpp"std::vector", header"<vector>".} = object
|
||||||
|
|
||||||
proc newVector[T](len: int): ptr std_vector[T] {.importcpp: "new std::vector<'1>(@)".}
|
proc newVector[T](len: int): ptr std_vector[T] {.importcpp: "new std::vector<'1>(@)".}
|
||||||
proc deleteVector[T](v: ptr std_vector[T]) {.importcpp: "delete @; @ = NIM_NIL;".}
|
proc deleteVector[T](v: ptr std_vector[T]) {.importcpp: "delete @; @ = NIM_NIL;".}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
type
|
type
|
||||||
Base[T] = ref object {.inheritable.}
|
Base[T] {.inheritable.} = ref object
|
||||||
value*: T
|
value*: T
|
||||||
|
|
||||||
Derived[T] = ref object of Base[T]
|
Derived[T] = ref object of Base[T]
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ block tinherit:
|
||||||
|
|
||||||
block tspecialise:
|
block tspecialise:
|
||||||
type
|
type
|
||||||
TGen[T] = object {.inheritable.}
|
TGen[T] {.inheritable.} = object
|
||||||
TSpef = object of TGen[string]
|
TSpef = object of TGen[string]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import strutils
|
||||||
|
|
||||||
type
|
type
|
||||||
PNode[T,D] = ref TNode[T,D]
|
PNode[T,D] = ref TNode[T,D]
|
||||||
TItem {.acyclic, pure, final, shallow.} [T,D] = object
|
TItem[T,D] {.acyclic, pure, final, shallow.} = object
|
||||||
key: T
|
key: T
|
||||||
value: D
|
value: D
|
||||||
node: PNode[T,D]
|
node: PNode[T,D]
|
||||||
|
|
@ -20,7 +20,7 @@ type
|
||||||
val_set: bool
|
val_set: bool
|
||||||
|
|
||||||
TItems[T,D] = seq[ref TItem[T,D]]
|
TItems[T,D] = seq[ref TItem[T,D]]
|
||||||
TNode {.acyclic, pure, final, shallow.} [T,D] = object
|
TNode[T,D] {.acyclic, pure, final, shallow.} = object
|
||||||
slots: TItems[T,D]
|
slots: TItems[T,D]
|
||||||
left: PNode[T,D]
|
left: PNode[T,D]
|
||||||
count: int32
|
count: int32
|
||||||
|
|
|
||||||
10
tests/generics/tinheritable_importcpp.nim
Normal file
10
tests/generics/tinheritable_importcpp.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
discard """
|
||||||
|
targets: "cpp"
|
||||||
|
action: compile
|
||||||
|
"""
|
||||||
|
|
||||||
|
# #4651
|
||||||
|
type
|
||||||
|
Vector[T] {.importcpp: "std::vector<'0 >", header: "vector", inheritable.} = object
|
||||||
|
VectorDerived {.importcpp: "SomeVectorDerived", nodecl.} = object of Vector[int]
|
||||||
|
# Error: inheritance only works with non-final objects
|
||||||
|
|
@ -17,7 +17,7 @@ type
|
||||||
TSlotEnum = enum seEmpty, seFilled, seDeleted
|
TSlotEnum = enum seEmpty, seFilled, seDeleted
|
||||||
TKeyValuePair[A, B] = tuple[slot: TSlotEnum, key: A, val: B]
|
TKeyValuePair[A, B] = tuple[slot: TSlotEnum, key: A, val: B]
|
||||||
TKeyValuePairSeq[A, B] = seq[TKeyValuePair[A, B]]
|
TKeyValuePairSeq[A, B] = seq[TKeyValuePair[A, B]]
|
||||||
TTable* {.final.}[A, B] = object
|
TTable*[A, B] {.final.} = object
|
||||||
data: TKeyValuePairSeq[A, B]
|
data: TKeyValuePairSeq[A, B]
|
||||||
counter: int
|
counter: int
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,14 +191,14 @@ template myAttr3() {.pragma.}
|
||||||
template serializationKey(key: string) {.pragma.}
|
template serializationKey(key: string) {.pragma.}
|
||||||
|
|
||||||
type
|
type
|
||||||
MyObj = object {.packed,myAttr,serializationKey: "one".}
|
MyObj {.packed,myAttr,serializationKey: "one".} = object
|
||||||
myField {.myAttr2,serializationKey: "two".}: int
|
myField {.myAttr2,serializationKey: "two".}: int
|
||||||
myField2 {.myAttr3,serializationKey: "three".}: float
|
myField2 {.myAttr3,serializationKey: "three".}: float
|
||||||
|
|
||||||
# field pragmas not currently supported
|
# field pragmas not currently supported
|
||||||
test(MyObj):
|
test(MyObj):
|
||||||
type
|
type
|
||||||
_ = object {.packed,myAttr,serializationKey: "one".}
|
_ {.packed,myAttr,serializationKey: "one".} = object
|
||||||
myField: int
|
myField: int
|
||||||
myField2: float
|
myField2: float
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ type
|
||||||
# it's also possible to use a strongly typed tuple here
|
# it's also possible to use a strongly typed tuple here
|
||||||
VTable = array[0..1, pointer]
|
VTable = array[0..1, pointer]
|
||||||
|
|
||||||
TBase = object {.inheritable.}
|
TBase {.inheritable.} = object
|
||||||
vtbl: ptr VTable
|
vtbl: ptr VTable
|
||||||
|
|
||||||
TUserObject1 = object of TBase
|
TUserObject1 = object of TBase
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ type B
|
||||||
|
|
||||||
|
|
||||||
# bug #1659
|
# bug #1659
|
||||||
type Animal = ref object {.inheritable.}
|
type Animal {.inheritable.} = ref object
|
||||||
type Dog = ref object of Animal
|
type Dog = ref object of Animal
|
||||||
|
|
||||||
method say(a: Animal): auto {.base.} = "wat!"
|
method say(a: Animal): auto {.base.} = "wat!"
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ method somethin(obj: RootObj) {.base.} =
|
||||||
echo "do nothing"
|
echo "do nothing"
|
||||||
|
|
||||||
type
|
type
|
||||||
TNode* = object {.inheritable.}
|
TNode* {.inheritable.} = object
|
||||||
PNode* = ref TNode
|
PNode* = ref TNode
|
||||||
|
|
||||||
PNodeFoo* = ref object of TNode
|
PNodeFoo* = ref object of TNode
|
||||||
|
|
@ -30,7 +30,7 @@ o.somethin()
|
||||||
|
|
||||||
# tmproto
|
# tmproto
|
||||||
type
|
type
|
||||||
Obj1 = ref object {.inheritable.}
|
Obj1 {.inheritable.} = ref object
|
||||||
Obj2 = ref object of Obj1
|
Obj2 = ref object of Obj1
|
||||||
|
|
||||||
method beta(x: Obj1): int {.base.}
|
method beta(x: Obj1): int {.base.}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ do nothing
|
||||||
|
|
||||||
# tmultim2
|
# tmultim2
|
||||||
type
|
type
|
||||||
TThing = object {.inheritable.}
|
TThing {.inheritable.} = object
|
||||||
TUnit = object of TThing
|
TUnit = object of TThing
|
||||||
x: int
|
x: int
|
||||||
TParticle = object of TThing
|
TParticle = object of TThing
|
||||||
|
|
@ -49,7 +49,7 @@ staticCollide(a, b)
|
||||||
|
|
||||||
# tmultim6
|
# tmultim6
|
||||||
type
|
type
|
||||||
Thing = object {.inheritable.}
|
Thing {.inheritable.} = object
|
||||||
Unit[T] = object of Thing
|
Unit[T] = object of Thing
|
||||||
x: T
|
x: T
|
||||||
Particle = object of Thing
|
Particle = object of Thing
|
||||||
|
|
@ -81,7 +81,7 @@ method somethin(obj: RootObj) {.base.} =
|
||||||
echo "do nothing"
|
echo "do nothing"
|
||||||
|
|
||||||
type
|
type
|
||||||
TNode* = object {.inheritable.}
|
TNode* {.inheritable.} = object
|
||||||
PNode* = ref TNode
|
PNode* = ref TNode
|
||||||
|
|
||||||
PNodeFoo* = ref object of TNode
|
PNodeFoo* = ref object of TNode
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ type
|
||||||
TSlotEnum = enum seEmpty, seFilled, seDeleted
|
TSlotEnum = enum seEmpty, seFilled, seDeleted
|
||||||
TKeyValuePair[A, B] = tuple[slot: TSlotEnum, key: A, val: B]
|
TKeyValuePair[A, B] = tuple[slot: TSlotEnum, key: A, val: B]
|
||||||
TKeyValuePairSeq[A, B] = seq[TKeyValuePair[A, B]]
|
TKeyValuePairSeq[A, B] = seq[TKeyValuePair[A, B]]
|
||||||
TTable* {.final, myShallow.}[A, B] = object
|
TTable*[A, B] {.final, myShallow.} = object
|
||||||
data: TKeyValuePairSeq[A, B]
|
data: TKeyValuePairSeq[A, B]
|
||||||
counter: int
|
counter: int
|
||||||
|
|
||||||
|
|
@ -137,8 +137,7 @@ proc `$`*[A, B](t: TTable[A, B]): string =
|
||||||
# ------------------------------ count tables -------------------------------
|
# ------------------------------ count tables -------------------------------
|
||||||
|
|
||||||
type
|
type
|
||||||
TCountTable* {.final, myShallow.}[
|
TCountTable*[A] {.final, myShallow.} = object ## table that counts the number of each key
|
||||||
A] = object ## table that counts the number of each key
|
|
||||||
data: seq[tuple[key: A, val: int]]
|
data: seq[tuple[key: A, val: int]]
|
||||||
counter: int
|
counter: int
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ echo s[0].x
|
||||||
|
|
||||||
# bug #563
|
# bug #563
|
||||||
type
|
type
|
||||||
Foo =
|
Foo {.inheritable.} =
|
||||||
object {.inheritable.}
|
object
|
||||||
x: int
|
x: int
|
||||||
|
|
||||||
Bar =
|
Bar =
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ block tobject2:
|
||||||
|
|
||||||
block tofopr:
|
block tofopr:
|
||||||
type
|
type
|
||||||
TMyType = object {.inheritable.}
|
TMyType {.inheritable.} = object
|
||||||
len: int
|
len: int
|
||||||
data: string
|
data: string
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,12 @@ struct SimpleStruct {
|
||||||
""" .}
|
""" .}
|
||||||
|
|
||||||
type
|
type
|
||||||
GenericIntType {.importcpp: "GenericIntType<'0, '1>".} [N: static[int]; T] = object
|
GenericIntType[N: static[int]; T] {.importcpp: "GenericIntType<'0, '1>".} = object
|
||||||
data: array[N, T]
|
data: array[N, T]
|
||||||
|
|
||||||
GenericIntTypeAlt {.importcpp: "GenericIntType".} [N: static[int]; T] = object
|
GenericIntTypeAlt[N: static[int]; T] {.importcpp: "GenericIntType".} = object
|
||||||
|
|
||||||
GenericTType {.importcpp: "GenericTType<'0>".} [T] = object
|
GenericTType[T] {.importcpp: "GenericTType<'0>".} = object
|
||||||
field: T
|
field: T
|
||||||
|
|
||||||
GenInt4 = GenericIntType[4, int]
|
GenInt4 = GenericIntType[4, int]
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
type
|
type
|
||||||
TRadixNodeKind = enum rnLinear, rnFull, rnLeaf
|
TRadixNodeKind = enum rnLinear, rnFull, rnLeaf
|
||||||
PRadixNode = ref TRadixNode
|
PRadixNode = ref TRadixNode
|
||||||
TRadixNode = object {.inheritable.}
|
TRadixNode {.inheritable.} = object
|
||||||
kind: TRadixNodeKind
|
kind: TRadixNodeKind
|
||||||
TRadixNodeLinear = object of TRadixNode
|
TRadixNodeLinear = object of TRadixNode
|
||||||
len: int8
|
len: int8
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
type
|
type
|
||||||
TAnimal=object {.inheritable.}
|
TAnimal{.inheritable.}=object
|
||||||
PAnimal=ref TAnimal
|
PAnimal=ref TAnimal
|
||||||
|
|
||||||
TDog=object of TAnimal
|
TDog=object of TAnimal
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ discard """
|
||||||
"""
|
"""
|
||||||
|
|
||||||
type
|
type
|
||||||
TA = object {.pure, final.}
|
TA {.pure, final.} = object
|
||||||
x: string
|
x: string
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@ ob = T[int](elem: 23)
|
||||||
doAssert ob.elem == 23
|
doAssert ob.elem == 23
|
||||||
|
|
||||||
type
|
type
|
||||||
TTreeIteratorA* = ref object {.inheritable.}
|
TTreeIteratorA* {.inheritable.} = ref object
|
||||||
|
|
||||||
TKeysIteratorA* = ref object of TTreeIteratorA #compiles
|
TKeysIteratorA* = ref object of TTreeIteratorA #compiles
|
||||||
|
|
||||||
TTreeIterator* [T,D] = ref object {.inheritable.}
|
TTreeIterator* [T,D] {.inheritable.} = ref object
|
||||||
|
|
||||||
TKeysIterator* [T,D] = ref object of TTreeIterator[T,D] #this not
|
TKeysIterator* [T,D] = ref object of TTreeIterator[T,D] #this not
|
||||||
|
|
||||||
|
|
|
||||||
5
tests/types/told_pragma_syntax1.nim
Normal file
5
tests/types/told_pragma_syntax1.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "invalid indentation"
|
||||||
|
"""
|
||||||
|
|
||||||
|
type Foo = object {.final.}
|
||||||
5
tests/types/told_pragma_syntax2.nim
Normal file
5
tests/types/told_pragma_syntax2.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "invalid indentation"
|
||||||
|
"""
|
||||||
|
|
||||||
|
type Bar {.final.} [T] = object
|
||||||
|
|
@ -3,6 +3,9 @@
|
||||||
|
|
||||||
import std / [strutils, sets]
|
import std / [strutils, sets]
|
||||||
|
|
||||||
|
when defined(nimPreviewSlimSystem):
|
||||||
|
import std/syncio
|
||||||
|
|
||||||
import ".." / compiler / [
|
import ".." / compiler / [
|
||||||
llstream, lexer, options, msgs, idents,
|
llstream, lexer, options, msgs, idents,
|
||||||
lineinfos, pathutils]
|
lineinfos, pathutils]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue