mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-24 00:05:25 +00:00
many bugfixes for js (#14158)
* many bugfixes for js fixes #12672, fixes #14153, closes #14123, closes #11331, fixes #11783, fixes #13966, fixes #14087, fixes #14117, closes #12256. mostly fixes the fact that it was allowed to assign to newly created temp variables. additionally attempts to get rid of null initialized seqs/strings (though they might pop up here and there); this simplifies a lot of things and makes code size smaller. even if null seqs/strings pop up here and there it's still better than all those bugs existing. * formatting fixes * CI fixes * more CI fixes
This commit is contained in:
12
tests/js/t12672.nim
Normal file
12
tests/js/t12672.nim
Normal file
@@ -0,0 +1,12 @@
|
||||
discard """
|
||||
output: ""
|
||||
"""
|
||||
|
||||
proc foo =
|
||||
var x: seq[seq[int]]
|
||||
for row in x.mitems:
|
||||
let i = 1
|
||||
echo row
|
||||
inc row[i-1]
|
||||
|
||||
foo()
|
||||
22
tests/js/t14153.nim
Normal file
22
tests/js/t14153.nim
Normal file
@@ -0,0 +1,22 @@
|
||||
discard """
|
||||
output: '''
|
||||
index 5 not in 0 .. 2
|
||||
index 5 not in 0 .. 2
|
||||
'''
|
||||
"""
|
||||
|
||||
var x = @[1, 2, 3]
|
||||
|
||||
try:
|
||||
echo x[5]
|
||||
except IndexError:
|
||||
echo getCurrentExceptionMsg()
|
||||
except:
|
||||
doAssert false
|
||||
|
||||
try:
|
||||
x[5] = 8
|
||||
except IndexError:
|
||||
echo getCurrentExceptionMsg()
|
||||
except:
|
||||
doAssert false
|
||||
@@ -1,4 +1,5 @@
|
||||
discard """
|
||||
cmd: "nim $target $options --stackTrace:off --lineTrace:off $file"
|
||||
output: "Hello World"
|
||||
maxcodesize: 1000
|
||||
ccodecheck: "!@'function'"
|
||||
@@ -7,4 +8,3 @@ discard """
|
||||
import jsconsole
|
||||
|
||||
console.log "Hello World"
|
||||
|
||||
|
||||
9
tests/js/tjshello_stacktrace.nim
Normal file
9
tests/js/tjshello_stacktrace.nim
Normal file
@@ -0,0 +1,9 @@
|
||||
discard """
|
||||
output: "Hello World"
|
||||
maxcodesize: 4500
|
||||
ccodecheck: "!@'function'"
|
||||
"""
|
||||
|
||||
import jsconsole
|
||||
|
||||
console.log "Hello World"
|
||||
@@ -62,8 +62,8 @@ block:
|
||||
result = result and obj1.`&&`.addr[] == "bar".cstring
|
||||
result = result and obj2.`if` == 0
|
||||
result = result and obj2.`for` == 0
|
||||
result = result and obj2.`==`.isNil()
|
||||
result = result and obj2.`&&`.isNil()
|
||||
result = result and obj2.`==`.len == 0
|
||||
result = result and obj2.`&&`.len == 0
|
||||
echo test()
|
||||
|
||||
# Test codegen for fields with uppercase letters:
|
||||
|
||||
@@ -308,21 +308,21 @@ b = 0,
|
||||
c = 0.0,
|
||||
d = '\0',
|
||||
e = eA,
|
||||
f = nil,
|
||||
f = "",
|
||||
g = {},
|
||||
h = {},
|
||||
i = [nil, nil, nil],
|
||||
j = nil,
|
||||
i = ["", "", ""],
|
||||
j = @[],
|
||||
k = 0,
|
||||
l = [a = nil,
|
||||
b = nil],
|
||||
l = [a = "",
|
||||
b = @[]],
|
||||
m = nil,
|
||||
n = nil,
|
||||
o = [Field0 = [a = nil,
|
||||
b = nil],
|
||||
Field1 = nil],
|
||||
o = [Field0 = [a = "",
|
||||
b = @[]],
|
||||
Field1 = ""],
|
||||
p = nil,
|
||||
q = nil]
|
||||
q = ""]
|
||||
""")
|
||||
doAssert(repr(cc) == """
|
||||
[a = 12,
|
||||
|
||||
79
tests/js/ttempgen.nim
Normal file
79
tests/js/ttempgen.nim
Normal file
@@ -0,0 +1,79 @@
|
||||
discard """
|
||||
output: '''
|
||||
foo
|
||||
'''
|
||||
"""
|
||||
|
||||
block: # #12672
|
||||
var a = @[1]
|
||||
let i = 1
|
||||
inc a[i-1]
|
||||
|
||||
var b: seq[int]
|
||||
doAssertRaises(IndexDefect): inc b[0]
|
||||
doAssertRaises(IndexDefect): inc b[i-1]
|
||||
|
||||
var x: seq[seq[int]]
|
||||
doAssertRaises(IndexDefect): # not TypeError
|
||||
inc x[0][i-1]
|
||||
|
||||
block: # #14087
|
||||
type Obj = object
|
||||
str: string
|
||||
|
||||
var s = @[Obj(str: "abc"), Obj(str: "def")]
|
||||
s[1].str.add("ghi")
|
||||
s[s.len - 1].str.add("jkl")
|
||||
s[^1].str.add("mno")
|
||||
s[s.high].str.add("pqr")
|
||||
|
||||
let slen = s.len
|
||||
s[slen - 1].str.add("stu")
|
||||
|
||||
let shigh = s.high
|
||||
s[shigh].str.add("vwx")
|
||||
|
||||
proc foo(): int =
|
||||
echo "foo"
|
||||
shigh
|
||||
s[foo()].str.add("yz")
|
||||
doAssert s[1].str == "defghijklmnopqrstuvwxyz"
|
||||
|
||||
block: # #14117
|
||||
type
|
||||
A = object
|
||||
case kind: bool
|
||||
of true:
|
||||
sons: seq[int]
|
||||
else: discard
|
||||
|
||||
var a = A(kind: true)
|
||||
doAssert a.sons.len == 0
|
||||
a.sons.add(1)
|
||||
doAssert a.sons.len == 1
|
||||
|
||||
import tables
|
||||
|
||||
block: # #13966
|
||||
var t: Table[int8, array[int8, seq[tuple[]]]]
|
||||
|
||||
t[0] = default(array[int8, seq[tuple[]]])
|
||||
t[0][0].add ()
|
||||
|
||||
block: # #11783
|
||||
proc fun(): string =
|
||||
discard
|
||||
|
||||
var ret: string
|
||||
ret.add fun()
|
||||
doAssert ret == ""
|
||||
|
||||
block: # #12256
|
||||
var x: bool
|
||||
|
||||
doAssert x == false
|
||||
|
||||
reset x
|
||||
|
||||
doAssert x == false
|
||||
doAssert x != true
|
||||
Reference in New Issue
Block a user