mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-07 04:14:19 +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:
@@ -80,7 +80,7 @@ block tcopy:
|
||||
|
||||
block tgenericassign:
|
||||
type
|
||||
TAny = object {.pure.}
|
||||
TAny {.pure.} = object
|
||||
value: pointer
|
||||
rawType: pointer
|
||||
|
||||
|
||||
@@ -561,7 +561,7 @@ when isMainModule:
|
||||
echo "got the ident m"
|
||||
|
||||
testRecCase:
|
||||
type Obj[T] = object {.inheritable.}
|
||||
type Obj[T] {.inheritable.} = object
|
||||
name: string
|
||||
case isFat: bool
|
||||
of true:
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
discard """
|
||||
errormsg: "ambiguous call"
|
||||
file: "tbind2.nim"
|
||||
line: 12
|
||||
file: "told_bind_expr.nim"
|
||||
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: int, y: int8): int = return x - y
|
||||
@@ -29,7 +29,7 @@ template test =
|
||||
var b = 1
|
||||
say (b += 1; b), (b += 1; b) #2,3
|
||||
|
||||
type C = object {.byRef.}
|
||||
type C {.byRef.} = object
|
||||
i: int
|
||||
|
||||
proc say(a, b: C) =
|
||||
|
||||
@@ -7,7 +7,7 @@ type
|
||||
Features: seq[Feature] # Read-Only
|
||||
|
||||
PNode* = ref Node
|
||||
Node = object {.inheritable.}
|
||||
Node {.inheritable.} = object
|
||||
attributes*: seq[PAttr]
|
||||
childNodes*: seq[PNode]
|
||||
FLocalName: string # Read-only
|
||||
|
||||
@@ -11,7 +11,7 @@ type
|
||||
className* : string
|
||||
TClassOfTobj = object of TClassOfTCustomObject
|
||||
nil
|
||||
TCustomObject = ref object {.inheritable.}
|
||||
TCustomObject {.inheritable.} = ref object
|
||||
class* : ptr TClassOfTCustomObject
|
||||
TObj = ref object of TCustomObject
|
||||
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 foo(): C[int] =
|
||||
|
||||
@@ -8,7 +8,7 @@ disabled: "windows" # pending bug #18011
|
||||
|
||||
# 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) =
|
||||
{.emit: [v, "[", key, "] = ", val, ";"].}
|
||||
|
||||
@@ -12,8 +12,8 @@ struct Vector {
|
||||
""".}
|
||||
|
||||
type
|
||||
Vector {.importcpp: "Vector".} [T] = object
|
||||
VectorIterator {.importcpp: "Vector<'0>::Iterator".} [T] = object
|
||||
Vector[T] {.importcpp: "Vector".} = object
|
||||
VectorIterator[T] {.importcpp: "Vector<'0>::Iterator".} = object
|
||||
|
||||
var x: VectorIterator[void]
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ discard """
|
||||
"""
|
||||
{.push warningAsError[Effect]: on.}
|
||||
type
|
||||
TObj = object {.pure, inheritable.}
|
||||
TObj {.pure, inheritable.} = object
|
||||
TObjB = object of TObj
|
||||
a, b, c: string
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ discard """
|
||||
"""
|
||||
|
||||
type
|
||||
TObj = object {.pure, inheritable.}
|
||||
TObj {.pure, inheritable.} = object
|
||||
TObjB = object of TObj
|
||||
a, b, c: string
|
||||
fn: proc (): int {.tags: [].}
|
||||
|
||||
@@ -4,7 +4,7 @@ discard """
|
||||
"""
|
||||
|
||||
type
|
||||
TObj = object {.pure, inheritable.}
|
||||
TObj {.pure, inheritable.} = object
|
||||
TObjB = object of TObj
|
||||
a, b, c: string
|
||||
fn: proc (): int {.tags: [ReadIOEffect].}
|
||||
|
||||
@@ -9,7 +9,7 @@ tinvalidinout.nim(18, 9) Error: the 'in' modifier can be used only with imported
|
||||
"""
|
||||
|
||||
type
|
||||
Foo {.header: "foo.h", importcpp.} [in T] = object
|
||||
Foo[in T] {.header: "foo.h", importcpp.} = object
|
||||
|
||||
Bar[out X] = object
|
||||
x: int
|
||||
|
||||
@@ -76,7 +76,7 @@ doAssert(getCurrentException() == nil)
|
||||
# raise by pointer and also generic 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 deleteVector[T](v: ptr std_vector[T]) {.importcpp: "delete @; @ = NIM_NIL;".}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
type
|
||||
Base[T] = ref object {.inheritable.}
|
||||
Base[T] {.inheritable.} = ref object
|
||||
value*: T
|
||||
|
||||
Derived[T] = ref object of Base[T]
|
||||
|
||||
@@ -31,7 +31,7 @@ block tinherit:
|
||||
|
||||
block tspecialise:
|
||||
type
|
||||
TGen[T] = object {.inheritable.}
|
||||
TGen[T] {.inheritable.} = object
|
||||
TSpef = object of TGen[string]
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import strutils
|
||||
|
||||
type
|
||||
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
|
||||
value: D
|
||||
node: PNode[T,D]
|
||||
@@ -20,7 +20,7 @@ type
|
||||
val_set: bool
|
||||
|
||||
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]
|
||||
left: PNode[T,D]
|
||||
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
|
||||
TKeyValuePair[A, B] = tuple[slot: TSlotEnum, key: A, val: B]
|
||||
TKeyValuePairSeq[A, B] = seq[TKeyValuePair[A, B]]
|
||||
TTable* {.final.}[A, B] = object
|
||||
TTable*[A, B] {.final.} = object
|
||||
data: TKeyValuePairSeq[A, B]
|
||||
counter: int
|
||||
|
||||
|
||||
@@ -191,14 +191,14 @@ template myAttr3() {.pragma.}
|
||||
template serializationKey(key: string) {.pragma.}
|
||||
|
||||
type
|
||||
MyObj = object {.packed,myAttr,serializationKey: "one".}
|
||||
MyObj {.packed,myAttr,serializationKey: "one".} = object
|
||||
myField {.myAttr2,serializationKey: "two".}: int
|
||||
myField2 {.myAttr3,serializationKey: "three".}: float
|
||||
|
||||
# field pragmas not currently supported
|
||||
test(MyObj):
|
||||
type
|
||||
_ = object {.packed,myAttr,serializationKey: "one".}
|
||||
_ {.packed,myAttr,serializationKey: "one".} = object
|
||||
myField: int
|
||||
myField2: float
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ type
|
||||
# it's also possible to use a strongly typed tuple here
|
||||
VTable = array[0..1, pointer]
|
||||
|
||||
TBase = object {.inheritable.}
|
||||
TBase {.inheritable.} = object
|
||||
vtbl: ptr VTable
|
||||
|
||||
TUserObject1 = object of TBase
|
||||
|
||||
@@ -10,7 +10,7 @@ type B
|
||||
|
||||
|
||||
# bug #1659
|
||||
type Animal = ref object {.inheritable.}
|
||||
type Animal {.inheritable.} = ref object
|
||||
type Dog = ref object of Animal
|
||||
|
||||
method say(a: Animal): auto {.base.} = "wat!"
|
||||
|
||||
@@ -12,7 +12,7 @@ method somethin(obj: RootObj) {.base.} =
|
||||
echo "do nothing"
|
||||
|
||||
type
|
||||
TNode* = object {.inheritable.}
|
||||
TNode* {.inheritable.} = object
|
||||
PNode* = ref TNode
|
||||
|
||||
PNodeFoo* = ref object of TNode
|
||||
@@ -30,7 +30,7 @@ o.somethin()
|
||||
|
||||
# tmproto
|
||||
type
|
||||
Obj1 = ref object {.inheritable.}
|
||||
Obj1 {.inheritable.} = ref object
|
||||
Obj2 = ref object of Obj1
|
||||
|
||||
method beta(x: Obj1): int {.base.}
|
||||
|
||||
@@ -16,7 +16,7 @@ do nothing
|
||||
|
||||
# tmultim2
|
||||
type
|
||||
TThing = object {.inheritable.}
|
||||
TThing {.inheritable.} = object
|
||||
TUnit = object of TThing
|
||||
x: int
|
||||
TParticle = object of TThing
|
||||
@@ -49,7 +49,7 @@ staticCollide(a, b)
|
||||
|
||||
# tmultim6
|
||||
type
|
||||
Thing = object {.inheritable.}
|
||||
Thing {.inheritable.} = object
|
||||
Unit[T] = object of Thing
|
||||
x: T
|
||||
Particle = object of Thing
|
||||
@@ -81,7 +81,7 @@ method somethin(obj: RootObj) {.base.} =
|
||||
echo "do nothing"
|
||||
|
||||
type
|
||||
TNode* = object {.inheritable.}
|
||||
TNode* {.inheritable.} = object
|
||||
PNode* = ref TNode
|
||||
|
||||
PNodeFoo* = ref object of TNode
|
||||
|
||||
@@ -10,7 +10,7 @@ type
|
||||
TSlotEnum = enum seEmpty, seFilled, seDeleted
|
||||
TKeyValuePair[A, B] = tuple[slot: TSlotEnum, key: A, val: B]
|
||||
TKeyValuePairSeq[A, B] = seq[TKeyValuePair[A, B]]
|
||||
TTable* {.final, myShallow.}[A, B] = object
|
||||
TTable*[A, B] {.final, myShallow.} = object
|
||||
data: TKeyValuePairSeq[A, B]
|
||||
counter: int
|
||||
|
||||
@@ -137,8 +137,7 @@ proc `$`*[A, B](t: TTable[A, B]): string =
|
||||
# ------------------------------ count tables -------------------------------
|
||||
|
||||
type
|
||||
TCountTable* {.final, myShallow.}[
|
||||
A] = object ## table that counts the number of each key
|
||||
TCountTable*[A] {.final, myShallow.} = object ## table that counts the number of each key
|
||||
data: seq[tuple[key: A, val: int]]
|
||||
counter: int
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ echo s[0].x
|
||||
|
||||
# bug #563
|
||||
type
|
||||
Foo =
|
||||
object {.inheritable.}
|
||||
Foo {.inheritable.} =
|
||||
object
|
||||
x: int
|
||||
|
||||
Bar =
|
||||
|
||||
@@ -31,7 +31,7 @@ block tobject2:
|
||||
|
||||
block tofopr:
|
||||
type
|
||||
TMyType = object {.inheritable.}
|
||||
TMyType {.inheritable.} = object
|
||||
len: int
|
||||
data: string
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@ struct SimpleStruct {
|
||||
""" .}
|
||||
|
||||
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]
|
||||
|
||||
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
|
||||
|
||||
GenInt4 = GenericIntType[4, int]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
type
|
||||
TRadixNodeKind = enum rnLinear, rnFull, rnLeaf
|
||||
PRadixNode = ref TRadixNode
|
||||
TRadixNode = object {.inheritable.}
|
||||
TRadixNode {.inheritable.} = object
|
||||
kind: TRadixNodeKind
|
||||
TRadixNodeLinear = object of TRadixNode
|
||||
len: int8
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
type
|
||||
TAnimal=object {.inheritable.}
|
||||
TAnimal{.inheritable.}=object
|
||||
PAnimal=ref TAnimal
|
||||
|
||||
TDog=object of TAnimal
|
||||
|
||||
@@ -3,7 +3,7 @@ discard """
|
||||
"""
|
||||
|
||||
type
|
||||
TA = object {.pure, final.}
|
||||
TA {.pure, final.} = object
|
||||
x: string
|
||||
|
||||
var
|
||||
|
||||
@@ -11,11 +11,11 @@ ob = T[int](elem: 23)
|
||||
doAssert ob.elem == 23
|
||||
|
||||
type
|
||||
TTreeIteratorA* = ref object {.inheritable.}
|
||||
TTreeIteratorA* {.inheritable.} = ref object
|
||||
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user