parent
3215666e33
commit
bb532a697e
5 changed files with 51 additions and 5 deletions
|
|
@ -638,14 +638,22 @@ proc strTableIncl*(t: var TStrTable, n: PSym): bool {.discardable.} =
|
||||||
# This way the newest redefinition is picked by the semantic analyses!
|
# This way the newest redefinition is picked by the semantic analyses!
|
||||||
assert n.name != nil
|
assert n.name != nil
|
||||||
var h: THash = n.name.h and high(t.data)
|
var h: THash = n.name.h and high(t.data)
|
||||||
|
var replaceSlot = -1
|
||||||
while true:
|
while true:
|
||||||
var it = t.data[h]
|
var it = t.data[h]
|
||||||
if it == nil: break
|
if it == nil: break
|
||||||
|
# Semantic checking can happen multiple times thanks to templates
|
||||||
|
# and overloading: (var x=@[]; x).mapIt(it).
|
||||||
|
# So it is possible the very same sym is added multiple
|
||||||
|
# times to the symbol table which we allow here with the 'it == n' check.
|
||||||
if it.name.id == n.name.id and reallySameIdent(it.name.s, n.name.s):
|
if it.name.id == n.name.id and reallySameIdent(it.name.s, n.name.s):
|
||||||
t.data[h] = n # overwrite it with newer definition!
|
if it == n: return false
|
||||||
return true # found it
|
replaceSlot = h
|
||||||
h = nextTry(h, high(t.data))
|
h = nextTry(h, high(t.data))
|
||||||
if mustRehash(len(t.data), t.counter):
|
if replaceSlot >= 0:
|
||||||
|
t.data[replaceSlot] = n # overwrite it with newer definition!
|
||||||
|
return true # found it
|
||||||
|
elif mustRehash(len(t.data), t.counter):
|
||||||
strTableEnlarge(t)
|
strTableEnlarge(t)
|
||||||
strTableRawInsert(t.data, n)
|
strTableRawInsert(t.data, n)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -142,8 +142,8 @@ proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym =
|
||||||
proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym =
|
proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym =
|
||||||
# like newSymS, but considers gensym'ed symbols
|
# like newSymS, but considers gensym'ed symbols
|
||||||
if n.kind == nkSym:
|
if n.kind == nkSym:
|
||||||
|
# and sfGenSym in n.sym.flags:
|
||||||
result = n.sym
|
result = n.sym
|
||||||
internalAssert sfGenSym in result.flags
|
|
||||||
internalAssert result.kind == kind
|
internalAssert result.kind == kind
|
||||||
# when there is a nested proc inside a template, semtmpl
|
# when there is a nested proc inside a template, semtmpl
|
||||||
# will assign a wrong owner during the first pass over the
|
# will assign a wrong owner during the first pass over the
|
||||||
|
|
|
||||||
|
|
@ -306,6 +306,8 @@ proc handleGenericInvokation(cl: var TReplTypeVars, t: PType): PType =
|
||||||
newbody.deepCopy = cl.c.instDeepCopy(cl.c, dc, result, cl.info)
|
newbody.deepCopy = cl.c.instDeepCopy(cl.c, dc, result, cl.info)
|
||||||
|
|
||||||
proc eraseVoidParams*(t: PType) =
|
proc eraseVoidParams*(t: PType) =
|
||||||
|
# transform '(): void' into '()' because old parts of the compiler really
|
||||||
|
# doesn't deal with '(): void':
|
||||||
if t.sons[0] != nil and t.sons[0].kind == tyEmpty:
|
if t.sons[0] != nil and t.sons[0].kind == tyEmpty:
|
||||||
t.sons[0] = nil
|
t.sons[0] = nil
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2905,7 +2905,11 @@ proc `*=`*[T: float|float32|float64] (x: var T, y: T) {.inline, noSideEffect.} =
|
||||||
## Multiplies in place a floating point number
|
## Multiplies in place a floating point number
|
||||||
x = x * y
|
x = x * y
|
||||||
|
|
||||||
proc `/=`*[T: float|float32|float64] (x: var T, y: T) {.inline, noSideEffect.} =
|
proc `/=`*(x: var float64, y: float64) {.inline, noSideEffect.} =
|
||||||
|
## Divides in place a floating point number
|
||||||
|
x = x / y
|
||||||
|
|
||||||
|
proc `/=`*[T: float|float32](x: var T, y: T) {.inline, noSideEffect.} =
|
||||||
## Divides in place a floating point number
|
## Divides in place a floating point number
|
||||||
x = x / y
|
x = x / y
|
||||||
|
|
||||||
|
|
|
||||||
32
tests/template/twrongmapit.nim
Normal file
32
tests/template/twrongmapit.nim
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "'"
|
||||||
|
file: "sequtils.nim"
|
||||||
|
line: 416
|
||||||
|
"""
|
||||||
|
# unfortunately our tester doesn't support multiple lines of compiler
|
||||||
|
# error messages yet...
|
||||||
|
|
||||||
|
# bug #1562
|
||||||
|
type Foo* {.pure, final.} = object
|
||||||
|
elt: float
|
||||||
|
|
||||||
|
template defineOpAssign(T: expr, op: expr) {.immediate.} =
|
||||||
|
proc op*(v: var T, w: T) {.inline.} =
|
||||||
|
for i in 0..1:
|
||||||
|
op(v.elt, w.elt)
|
||||||
|
|
||||||
|
const ATTEMPT = 0
|
||||||
|
|
||||||
|
when ATTEMPT == 0:
|
||||||
|
# FAILS: defining `/=` with template calling template
|
||||||
|
# ERROR about sem.nim line 144
|
||||||
|
template defineOpAssigns(T: expr) {.immediate.} =
|
||||||
|
mixin `/=`
|
||||||
|
defineOpAssign(T, `/=`)
|
||||||
|
|
||||||
|
defineOpAssigns(Foo)
|
||||||
|
|
||||||
|
# bug #1543
|
||||||
|
import sequtils
|
||||||
|
|
||||||
|
(var i= @[""];i).mapIt(it)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue