remove {.this.} pragma, deprecated since 0.19 (#20201)
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
parent
3dbf2ac946
commit
f6eb1d4d7d
13 changed files with 28 additions and 158 deletions
|
|
@ -8,8 +8,6 @@ after 20 20'''
|
|||
joinable: false
|
||||
"""
|
||||
|
||||
{.this: self.}
|
||||
|
||||
type
|
||||
mystring = object
|
||||
len, cap: int
|
||||
|
|
@ -51,7 +49,7 @@ proc resize(self: var mystring) =
|
|||
if self.cap == 0: self.cap = 8
|
||||
else: self.cap = (self.cap * 3) shr 1
|
||||
if self.data == nil: inc allocCount
|
||||
self.data = cast[type(data)](realloc(self.data, self.cap + 1))
|
||||
self.data = cast[type(self.data)](realloc(self.data, self.cap + 1))
|
||||
|
||||
proc add*(self: var mystring; c: char) =
|
||||
if self.len >= self.cap: resize(self)
|
||||
|
|
@ -60,17 +58,17 @@ proc add*(self: var mystring; c: char) =
|
|||
inc self.len
|
||||
|
||||
proc ensure(self: var mystring; newLen: int) =
|
||||
if newLen >= cap:
|
||||
cap = max((cap * 3) shr 1, newLen)
|
||||
if cap > 0:
|
||||
if data == nil: inc allocCount
|
||||
data = cast[type(data)](realloc(data, cap + 1))
|
||||
if newLen >= self.cap:
|
||||
self.cap = max((self.cap * 3) shr 1, newLen)
|
||||
if self.cap > 0:
|
||||
if self.data == nil: inc allocCount
|
||||
self.data = cast[type(self.data)](realloc(self.data, self.cap + 1))
|
||||
|
||||
proc add*(self: var mystring; y: mystring) =
|
||||
let newLen = len + y.len
|
||||
let newLen = self.len + y.len
|
||||
ensure(self, newLen)
|
||||
copyMem(addr data[len], y.data, y.data.len + 1)
|
||||
len = newLen
|
||||
copyMem(addr self.data[self.len], y.data, y.data.len + 1)
|
||||
self.len = newLen
|
||||
|
||||
proc create*(lit: string): mystring =
|
||||
let newLen = lit.len
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
discard """
|
||||
output: '''0 -2 0
|
||||
0 -2'''
|
||||
"""
|
||||
|
||||
{.this: self.}
|
||||
|
||||
type
|
||||
Foo = object
|
||||
a, b, x: int
|
||||
|
||||
proc yay(self: Foo) =
|
||||
echo a, " ", b, " ", x
|
||||
|
||||
proc footest[T](self: var Foo, a: T) =
|
||||
b = 1+a
|
||||
yay()
|
||||
|
||||
proc nongeneric(self: Foo) =
|
||||
echo a, " ", b
|
||||
|
||||
var ff: Foo
|
||||
footest(ff, -3)
|
||||
ff.nongeneric
|
||||
|
||||
{.experimental.}
|
||||
using
|
||||
c: Foo
|
||||
x, y: int
|
||||
|
||||
proc usesSig(c) =
|
||||
echo "yummy"
|
||||
|
||||
proc foobar(c, y) =
|
||||
echo "yay"
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
discard """
|
||||
action: compile
|
||||
"""
|
||||
|
||||
# bug #4671
|
||||
{.experimental.}
|
||||
{.this: self.}
|
||||
type
|
||||
SomeObj = object
|
||||
f: int
|
||||
|
||||
proc f(num: int) =
|
||||
discard
|
||||
|
||||
var intptr: ptr int
|
||||
intptr.f() # compiles fine
|
||||
|
||||
proc doSomething(self: var SomeObj) =
|
||||
var pint: ptr int
|
||||
pint.f() # Error: expression '.(pint, "f")' cannot be called
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
# bug #4177
|
||||
|
||||
type
|
||||
Parent = object of RootObj
|
||||
parentField: int
|
||||
Child = object of Parent
|
||||
childField: int
|
||||
|
||||
{.this: self.}
|
||||
proc sumFields(self: Child): int =
|
||||
result = parentField + childField # Error: undeclared identifier: 'parentField'
|
||||
|
||||
proc sumFieldsWorks(self: Child): int =
|
||||
result = self.parentField + childField
|
||||
16
tests/usingstmt/tusingstmt.nim
Normal file
16
tests/usingstmt/tusingstmt.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
type
|
||||
Foo = object
|
||||
|
||||
using
|
||||
c: Foo
|
||||
x, y: int
|
||||
|
||||
proc usesSig(c) = discard
|
||||
|
||||
proc foobar(c, y) = discard
|
||||
|
||||
usesSig(Foo())
|
||||
foobar(Foo(), 123)
|
||||
doAssert not compiles(usesSig(123))
|
||||
doAssert not compiles(foobar(Foo(), Foo()))
|
||||
doAssert not compiles(foobar(123, 123))
|
||||
Loading…
Add table
Add a link
Reference in a new issue