diff options
author | flywind <43030857+xflywind@users.noreply.github.com> | 2021-01-10 15:51:29 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-10 21:51:29 +0000 |
commit | 2c6f5ae6815367dcb44e441c8f3bda2e2513b061 (patch) | |
tree | 19a35b466342d141512cc5adc49f10354cb96cbe /compiler | |
parent | f82100ac93ddb8977d2a404d2cd85975114f50ab (diff) | |
download | Nim-2c6f5ae6815367dcb44e441c8f3bda2e2513b061.tar.gz |
fix #16650 (#16660)
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/semfold.nim | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 3d0a9d0ae..4cc2dcba0 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -15,6 +15,8 @@ import platform, math, msgs, idents, renderer, types, commands, magicsys, modulegraphs, strtabs, lineinfos +from system/memory import nimCStrLen + proc errorType*(g: ModuleGraph): PType = ## creates a type representing an error state result = newType(tyError, nextTypeId(g.idgen), g.owners[^1]) @@ -133,7 +135,10 @@ proc evalOp(m: TMagic, n, a, b, c: PNode; g: ModuleGraph): PNode = if a.kind == nkNilLit: result = newIntNodeT(Zero, n, g) elif a.kind in {nkStrLit..nkTripleStrLit}: - result = newIntNodeT(toInt128(a.strVal.len), n, g) + if a.typ.kind == tyString: + result = newIntNodeT(toInt128(a.strVal.len), n, g) + elif a.typ.kind == tyCString: + result = newIntNodeT(toInt128(nimCStrLen(a.strVal)), n, g) else: result = newIntNodeT(toInt128(a.len), n, g) of mUnaryPlusI, mUnaryPlusF64: result = a # throw `+` away |