From 80107b360c8bb01efba39a9a4a0b9129b300a248 Mon Sep 17 00:00:00 2001 From: andri lim Date: Tue, 5 Jun 2018 09:18:20 +0700 Subject: [PATCH 1/4] add more test to 4799 --- compiler/ccgexprs.nim | 4 +- compiler/sigmatch.nim | 8 ++ tests/typerel/t4799.nim | 169 ++++++++++++++++++++++++++++++++++++++ tests/typerel/t4799_1.nim | 20 +++++ tests/typerel/t4799_2.nim | 24 ++++++ tests/typerel/t4799_3.nim | 24 ++++++ tests/typerel/t4799_4.nim | 23 ++++++ tests/typerel/t4799_5.nim | 23 ++++++ tests/typerel/t4799_6.nim | 20 +++++ tests/typerel/t4799_7.nim | 20 +++++ 10 files changed, 334 insertions(+), 1 deletion(-) create mode 100644 tests/typerel/t4799.nim create mode 100644 tests/typerel/t4799_1.nim create mode 100644 tests/typerel/t4799_2.nim create mode 100644 tests/typerel/t4799_3.nim create mode 100644 tests/typerel/t4799_4.nim create mode 100644 tests/typerel/t4799_5.nim create mode 100644 tests/typerel/t4799_6.nim create mode 100644 tests/typerel/t4799_7.nim diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 335aa2f84a..ad36d3e921 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -351,7 +351,9 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = else: useStringh(p.module) linefmt(p, cpsStmts, - "memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1[0])*$1Len_0);$n", + # bug #4799, keep the memcpy for a while + #"memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1[0])*$1Len_0);$n", + "$1 = $2;$n", rdLoc(dest), rdLoc(src)) of tySet: if mapType(ty) == ctArray: diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 41cac2a4af..fcfdda8bbe 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -2013,6 +2013,14 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType, if r == isGeneric: result.typ = getInstantiatedType(c, arg, m, base(f)) m.baseTypeMatch = true + # bug #4799, varargs accepting subtype relation object + elif r == isSubtype: + inc(m.subtypeMatches) + if f.kind == tyTypeDesc: + result = arg + else: + result = implicitConv(nkHiddenSubConv, f, arg, m, c) + m.baseTypeMatch = true else: result = userConvMatch(c, m, base(f), a, arg) if result != nil: m.baseTypeMatch = true diff --git a/tests/typerel/t4799.nim b/tests/typerel/t4799.nim new file mode 100644 index 0000000000..f1c283165f --- /dev/null +++ b/tests/typerel/t4799.nim @@ -0,0 +1,169 @@ +discard """ + output: "OK" +""" + +type + GRBase[T] = ref object of RootObj + val: T + GRC[T] = ref object of GRBase[T] + GRD[T] = ref object of GRBase[T] + +proc testGR[T](x: varargs[GRBase[T]]): string = + result = "" + for c in x: + result.add $c.val + +block test_t4799_1: + var rgv = GRBase[int](val: 3) + var rgc = GRC[int](val: 4) + var rgb = GRD[int](val: 2) + doAssert(testGR(rgb, rgc, rgv) == "243") + doAssert(testGR(rgc, rgv, rgb) == "432") + doAssert(testGR(rgv, rgb, rgc) == "324") + doAssert(testGR([rgb, rgc, rgv]) == "243") + doAssert(testGR([rgc, rgv, rgb]) == "432") + doAssert(testGR([rgv, rgb, rgc]) == "324") + +type + PRBase[T] = object of RootObj + val: T + PRC[T] = object of PRBase[T] + PRD[T] = object of PRBase[T] + +proc testPR[T](x: varargs[ptr PRBase[T]]): string = + result = "" + for c in x: + result.add $c.val + +block test_t4799_2: + var pgv = PRBase[int](val: 3) + var pgc = PRC[int](val: 4) + var pgb = PRD[int](val: 2) + doAssert(testPR(pgb.addr, pgc.addr, pgv.addr) == "243") + doAssert(testPR(pgc.addr, pgv.addr, pgb.addr) == "432") + doAssert(testPR(pgv.addr, pgb.addr, pgc.addr) == "324") + doAssert(testPR([pgb.addr, pgc.addr, pgv.addr]) == "243") + doAssert(testPR([pgc.addr, pgv.addr, pgb.addr]) == "432") + doAssert(testPR([pgv.addr, pgb.addr, pgc.addr]) == "324") + +type + RBase = ref object of RootObj + val: int + RC = ref object of RBase + RD = ref object of RBase + +proc testR(x: varargs[RBase]): string = + result = "" + for c in x: + result.add $c.val + +block test_t4799_3: + var rv = RBase(val: 3) + var rc = RC(val: 4) + var rb = RD(val: 2) + doAssert(testR(rb, rc, rv) == "243") + doAssert(testR(rc, rv, rb) == "432") + doAssert(testR(rv, rb, rc) == "324") + doAssert(testR([rb, rc, rv]) == "243") + doAssert(testR([rc, rv, rb]) == "432") + doAssert(testR([rv, rb, rc]) == "324") + +type + PBase = object of RootObj + val: int + PC = object of PBase + PD = object of PBase + +proc testP(x: varargs[ptr PBase]): string = + result = "" + for c in x: + result.add $c.val + +block test_t4799_4: + var pv = PBase(val: 3) + var pc = PC(val: 4) + var pb = PD(val: 2) + doAssert(testP(pb.addr, pc.addr, pv.addr) == "243") + doAssert(testP(pc.addr, pv.addr, pb.addr) == "432") + doAssert(testP(pv.addr, pb.addr, pc.addr) == "324") + doAssert(testP([pb.addr, pc.addr, pv.addr]) == "243") + doAssert(testP([pc.addr, pv.addr, pb.addr]) == "432") + doAssert(testP([pv.addr, pb.addr, pc.addr]) == "324") + +type + PSBase[T, V] = ref object of RootObj + val: T + color: V + PSRC[T] = ref object of PSBase[T, int] + PSRD[T] = ref object of PSBase[T, int] + +proc testPS[T, V](x: varargs[PSBase[T, V]]): string = + result = "" + for c in x: + result.add c.val + result.add $c.color + +block test_t4799_5: + var a = PSBase[string, int](val: "base", color: 1) + var b = PSRC[string](val: "rc", color: 2) + var c = PSRD[string](val: "rd", color: 3) + + doAssert(testPS(a, b, c) == "base1rc2rd3") + doAssert(testPS(b, a, c) == "rc2base1rd3") + doAssert(testPS(c, b, a) == "rd3rc2base1") + doAssert(testPS([a, b, c]) == "base1rc2rd3") + doAssert(testPS([b, a, c]) == "rc2base1rd3") + doAssert(testPS([c, b, a]) == "rd3rc2base1") + +type + SBase[T, V] = ref object of RootObj + val: T + color: V + SRC = ref object of SBase[string, int] + SRD = ref object of SBase[string, int] + +proc testS[T, V](x: varargs[SBase[T, V]]): string = + result = "" + for c in x: + result.add c.val + result.add $c.color + +block test_t4799_6: + var a = SBase[string, int](val: "base", color: 1) + var b = SRC(val: "rc", color: 2) + var c = SRD(val: "rd", color: 3) + + doAssert(testS(a, b, c) == "base1rc2rd3") + doAssert(testS(b, a, c) == "rc2base1rd3") + doAssert(testS(c, b, a) == "rd3rc2base1") + doAssert(testS([a, b, c]) == "base1rc2rd3") + # this is not varargs bug, but array construction bug + # see #7955 + #doAssert(testS([b, c, a]) == "rc2rd3base1") + #doAssert(testS([c, b, a]) == "rd3rc2base1") + +proc test_inproc() = + block test_inproc_1: + var rgv = GRBase[int](val: 3) + var rgc = GRC[int](val: 4) + var rgb = GRD[int](val: 2) + doAssert(testGR(rgb, rgc, rgv) == "243") + doAssert(testGR(rgc, rgv, rgb) == "432") + doAssert(testGR(rgv, rgb, rgc) == "324") + doAssert(testGR([rgb, rgc, rgv]) == "243") + doAssert(testGR([rgc, rgv, rgb]) == "432") + doAssert(testGR([rgv, rgb, rgc]) == "324") + + block test_inproc_2: + var pgv = PRBase[int](val: 3) + var pgc = PRC[int](val: 4) + var pgb = PRD[int](val: 2) + doAssert(testPR(pgb.addr, pgc.addr, pgv.addr) == "243") + doAssert(testPR(pgc.addr, pgv.addr, pgb.addr) == "432") + doAssert(testPR(pgv.addr, pgb.addr, pgc.addr) == "324") + doAssert(testPR([pgb.addr, pgc.addr, pgv.addr]) == "243") + doAssert(testPR([pgc.addr, pgv.addr, pgb.addr]) == "432") + doAssert(testPR([pgv.addr, pgb.addr, pgc.addr]) == "324") + +test_inproc() +echo "OK" diff --git a/tests/typerel/t4799_1.nim b/tests/typerel/t4799_1.nim new file mode 100644 index 0000000000..549b6bf3c5 --- /dev/null +++ b/tests/typerel/t4799_1.nim @@ -0,0 +1,20 @@ +discard """ + outputsub: '''ObjectAssignmentError''' + exitcode: "1" +""" + +type + Vehicle[T] = object of RootObj + tire: T + Car[T] = object of Vehicle[T] + Bike[T] = object of Vehicle[T] + +proc testVehicle[T](x: varargs[Vehicle[T]]): string = + result = "" + for c in x: + result.add $c.tire + +var v = Vehicle[int](tire: 3) +var c = Car[int](tire: 4) +var b = Bike[int](tire: 2) +echo testVehicle b, c, v diff --git a/tests/typerel/t4799_2.nim b/tests/typerel/t4799_2.nim new file mode 100644 index 0000000000..191a40469e --- /dev/null +++ b/tests/typerel/t4799_2.nim @@ -0,0 +1,24 @@ +discard """ +errormsg: "type mismatch: got " +nimout: '''t4799_2.nim(24, 18) Error: type mismatch: got +but expected one of: +proc testVehicle[T](x: varargs[Vehicle[T]]): string + +expression: testVehicle b''' +""" + +type + Vehicle[T] = ref object of RootObj + tire: T + Car[T] = object of Vehicle[T] + Bike[T] = object of Vehicle[T] + +proc testVehicle[T](x: varargs[Vehicle[T]]): string = + result = "" + for c in x: + result.add $c.tire + +var v = Vehicle[int](tire: 3) +var c = Car[int](tire: 4) +var b = Bike[int](tire: 2) +echo testVehicle b, c, v diff --git a/tests/typerel/t4799_3.nim b/tests/typerel/t4799_3.nim new file mode 100644 index 0000000000..a447da6b24 --- /dev/null +++ b/tests/typerel/t4799_3.nim @@ -0,0 +1,24 @@ +discard """ +errormsg: "Error: type mismatch: got " +nimout: '''t4799_3.nim(24, 18) Error: type mismatch: got +but expected one of: +proc testVehicle(x: varargs[Vehicle]): string + +expression: testVehicle b''' +""" + +type + Vehicle = ref object of RootObj + tire: int + Car = object of Vehicle + Bike = object of Vehicle + +proc testVehicle(x: varargs[Vehicle]): string = + result = "" + for c in x: + result.add $c.tire + +var v = Vehicle(tire: 3) +var c = Car(tire: 4) +var b = Bike(tire: 2) +echo testVehicle b, c, v \ No newline at end of file diff --git a/tests/typerel/t4799_4.nim b/tests/typerel/t4799_4.nim new file mode 100644 index 0000000000..52c45793c8 --- /dev/null +++ b/tests/typerel/t4799_4.nim @@ -0,0 +1,23 @@ +discard """ +errormsg: "type mismatch: got " +nimout: '''t4799_4.nim(23, 18) Error: type mismatch: got +but expected one of: +proc testVehicle[T](x: varargs[Vehicle[T]]): string + +expression: testVehicle b''' +""" + +type + Vehicle[T] = ptr object of RootObj + tire: T + Car[T] = object of Vehicle[T] + Bike[T] = object of Vehicle[T] + +proc testVehicle[T](x: varargs[Vehicle[T]]): string = + result = "" + for c in x: + result.add $c.tire + +var c = Car[int](tire: 4) +var b = Bike[int](tire: 2) +echo testVehicle b, c \ No newline at end of file diff --git a/tests/typerel/t4799_5.nim b/tests/typerel/t4799_5.nim new file mode 100644 index 0000000000..8c7fdc3135 --- /dev/null +++ b/tests/typerel/t4799_5.nim @@ -0,0 +1,23 @@ +discard """ +errormsg: "type mismatch: got " +nimout: '''t4799_5.nim(23, 18) Error: type mismatch: got +but expected one of: +proc testVehicle(x: varargs[Vehicle]): string + +expression: testVehicle b''' +""" + +type + Vehicle = ptr object of RootObj + tire: int + Car = object of Vehicle + Bike = object of Vehicle + +proc testVehicle(x: varargs[Vehicle]): string = + result = "" + for c in x: + result.add $c.tire + +var c = Car(tire: 4) +var b = Bike(tire: 2) +echo testVehicle b, c \ No newline at end of file diff --git a/tests/typerel/t4799_6.nim b/tests/typerel/t4799_6.nim new file mode 100644 index 0000000000..cfd399a6e0 --- /dev/null +++ b/tests/typerel/t4799_6.nim @@ -0,0 +1,20 @@ +discard """ + outputsub: '''ObjectAssignmentError''' + exitcode: "1" +""" + +type + Vehicle[T] = object of RootObj + tire: T + Car[T] = object of Vehicle[T] + Bike[T] = object of Vehicle[T] + +proc testVehicle[T](x: varargs[Vehicle[T]]): string = + result = "" + for c in x: + result.add $c.tire + +var v = Vehicle[int](tire: 3) +var c = Car[int](tire: 4) +var b = Bike[int](tire: 2) +echo testVehicle([b, c, v]) \ No newline at end of file diff --git a/tests/typerel/t4799_7.nim b/tests/typerel/t4799_7.nim new file mode 100644 index 0000000000..784eee8fc1 --- /dev/null +++ b/tests/typerel/t4799_7.nim @@ -0,0 +1,20 @@ +discard """ + outputsub: '''ObjectAssignmentError''' + exitcode: "1" +""" + +type + Vehicle = object of RootObj + tire: int + Car = object of Vehicle + Bike = object of Vehicle + +proc testVehicle(x: varargs[Vehicle]): string = + result = "" + for c in x: + result.add $c.tire + +var v = Vehicle(tire: 3) +var c = Car(tire: 4) +var b = Bike(tire: 2) +echo testVehicle([b, c, v]) \ No newline at end of file From 8063ecbb8fdd79f3a097789a72500a1663587bd5 Mon Sep 17 00:00:00 2001 From: andri lim Date: Tue, 5 Jun 2018 16:54:01 +0700 Subject: [PATCH 2/4] fix test case output --- tests/typerel/t4799_3.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/typerel/t4799_3.nim b/tests/typerel/t4799_3.nim index a447da6b24..aa2ddac56a 100644 --- a/tests/typerel/t4799_3.nim +++ b/tests/typerel/t4799_3.nim @@ -1,5 +1,5 @@ discard """ -errormsg: "Error: type mismatch: got " +errormsg: "type mismatch: got " nimout: '''t4799_3.nim(24, 18) Error: type mismatch: got but expected one of: proc testVehicle(x: varargs[Vehicle]): string From 436c1229563c6c44c85cf9b26814b0a4a45ef3f4 Mon Sep 17 00:00:00 2001 From: andri lim Date: Tue, 5 Jun 2018 22:16:53 +0700 Subject: [PATCH 3/4] combine/reduce test --- tests/typerel/t4799.nim | 82 +++++++++++++++++++++++++++++++++++++-- tests/typerel/t4799_2.nim | 12 ++---- tests/typerel/t4799_3.nim | 12 ++---- tests/typerel/t4799_4.nim | 23 ----------- tests/typerel/t4799_5.nim | 23 ----------- tests/typerel/t4799_6.nim | 20 ---------- tests/typerel/t4799_7.nim | 20 ---------- 7 files changed, 87 insertions(+), 105 deletions(-) delete mode 100644 tests/typerel/t4799_4.nim delete mode 100644 tests/typerel/t4799_5.nim delete mode 100644 tests/typerel/t4799_6.nim delete mode 100644 tests/typerel/t4799_7.nim diff --git a/tests/typerel/t4799.nim b/tests/typerel/t4799.nim index f1c283165f..89312950fe 100644 --- a/tests/typerel/t4799.nim +++ b/tests/typerel/t4799.nim @@ -142,7 +142,7 @@ block test_t4799_6: #doAssert(testS([b, c, a]) == "rc2rd3base1") #doAssert(testS([c, b, a]) == "rd3rc2base1") -proc test_inproc() = +proc test_inproc() = block test_inproc_1: var rgv = GRBase[int](val: 3) var rgc = GRC[int](val: 4) @@ -153,7 +153,7 @@ proc test_inproc() = doAssert(testGR([rgb, rgc, rgv]) == "243") doAssert(testGR([rgc, rgv, rgb]) == "432") doAssert(testGR([rgv, rgb, rgc]) == "324") - + block test_inproc_2: var pgv = PRBase[int](val: 3) var pgc = PRC[int](val: 4) @@ -164,6 +164,82 @@ proc test_inproc() = doAssert(testPR([pgb.addr, pgc.addr, pgv.addr]) == "243") doAssert(testPR([pgc.addr, pgv.addr, pgb.addr]) == "432") doAssert(testPR([pgv.addr, pgb.addr, pgc.addr]) == "324") - + test_inproc() + +template reject(x) = + static: assert(not compiles(x)) + +block test_t4799_7: + type + Vehicle[T] = ref object of RootObj + tire: T + Car[T] = object of Vehicle[T] + Bike[T] = object of Vehicle[T] + + proc testVehicle[T](x: varargs[Vehicle[T]]): string {.used.} = + result = "" + for c in x: + result.add $c.tire + + var v = Vehicle[int](tire: 3) + var c = Car[int](tire: 4) + var b = Bike[int](tire: 2) + + reject: + echo testVehicle b, c, v + +block test_t4799_8: + type + Vehicle = ref object of RootObj + tire: int + Car = object of Vehicle + Bike = object of Vehicle + + proc testVehicle(x: varargs[Vehicle]): string {.used.} = + result = "" + for c in x: + result.add $c.tire + + var v = Vehicle(tire: 3) + var c = Car(tire: 4) + var b = Bike(tire: 2) + + reject: + echo testVehicle b, c, v + +type + PGVehicle[T] = ptr object of RootObj + tire: T + PGCar[T] = object of PGVehicle[T] + PGBike[T] = object of PGVehicle[T] + +proc testVehicle[T](x: varargs[PGVehicle[T]]): string {.used.} = + result = "" + for c in x: + result.add $c.tire + +var pgc = PGCar[int](tire: 4) +var pgb = PGBike[int](tire: 2) + +reject: + echo testVehicle pgb, pgc + +type + RVehicle = ptr object of RootObj + tire: int + RCar = object of RVehicle + RBike = object of RVehicle + +proc testVehicle(x: varargs[RVehicle]): string {.used.} = + result = "" + for c in x: + result.add $c.tire + +var rc = RCar(tire: 4) +var rb = RBike(tire: 2) + +reject: + echo testVehicle rb, rc + echo "OK" diff --git a/tests/typerel/t4799_2.nim b/tests/typerel/t4799_2.nim index 191a40469e..cfd399a6e0 100644 --- a/tests/typerel/t4799_2.nim +++ b/tests/typerel/t4799_2.nim @@ -1,14 +1,10 @@ discard """ -errormsg: "type mismatch: got " -nimout: '''t4799_2.nim(24, 18) Error: type mismatch: got -but expected one of: -proc testVehicle[T](x: varargs[Vehicle[T]]): string - -expression: testVehicle b''' + outputsub: '''ObjectAssignmentError''' + exitcode: "1" """ type - Vehicle[T] = ref object of RootObj + Vehicle[T] = object of RootObj tire: T Car[T] = object of Vehicle[T] Bike[T] = object of Vehicle[T] @@ -21,4 +17,4 @@ proc testVehicle[T](x: varargs[Vehicle[T]]): string = var v = Vehicle[int](tire: 3) var c = Car[int](tire: 4) var b = Bike[int](tire: 2) -echo testVehicle b, c, v +echo testVehicle([b, c, v]) \ No newline at end of file diff --git a/tests/typerel/t4799_3.nim b/tests/typerel/t4799_3.nim index aa2ddac56a..784eee8fc1 100644 --- a/tests/typerel/t4799_3.nim +++ b/tests/typerel/t4799_3.nim @@ -1,14 +1,10 @@ discard """ -errormsg: "type mismatch: got " -nimout: '''t4799_3.nim(24, 18) Error: type mismatch: got -but expected one of: -proc testVehicle(x: varargs[Vehicle]): string - -expression: testVehicle b''' + outputsub: '''ObjectAssignmentError''' + exitcode: "1" """ type - Vehicle = ref object of RootObj + Vehicle = object of RootObj tire: int Car = object of Vehicle Bike = object of Vehicle @@ -21,4 +17,4 @@ proc testVehicle(x: varargs[Vehicle]): string = var v = Vehicle(tire: 3) var c = Car(tire: 4) var b = Bike(tire: 2) -echo testVehicle b, c, v \ No newline at end of file +echo testVehicle([b, c, v]) \ No newline at end of file diff --git a/tests/typerel/t4799_4.nim b/tests/typerel/t4799_4.nim deleted file mode 100644 index 52c45793c8..0000000000 --- a/tests/typerel/t4799_4.nim +++ /dev/null @@ -1,23 +0,0 @@ -discard """ -errormsg: "type mismatch: got " -nimout: '''t4799_4.nim(23, 18) Error: type mismatch: got -but expected one of: -proc testVehicle[T](x: varargs[Vehicle[T]]): string - -expression: testVehicle b''' -""" - -type - Vehicle[T] = ptr object of RootObj - tire: T - Car[T] = object of Vehicle[T] - Bike[T] = object of Vehicle[T] - -proc testVehicle[T](x: varargs[Vehicle[T]]): string = - result = "" - for c in x: - result.add $c.tire - -var c = Car[int](tire: 4) -var b = Bike[int](tire: 2) -echo testVehicle b, c \ No newline at end of file diff --git a/tests/typerel/t4799_5.nim b/tests/typerel/t4799_5.nim deleted file mode 100644 index 8c7fdc3135..0000000000 --- a/tests/typerel/t4799_5.nim +++ /dev/null @@ -1,23 +0,0 @@ -discard """ -errormsg: "type mismatch: got " -nimout: '''t4799_5.nim(23, 18) Error: type mismatch: got -but expected one of: -proc testVehicle(x: varargs[Vehicle]): string - -expression: testVehicle b''' -""" - -type - Vehicle = ptr object of RootObj - tire: int - Car = object of Vehicle - Bike = object of Vehicle - -proc testVehicle(x: varargs[Vehicle]): string = - result = "" - for c in x: - result.add $c.tire - -var c = Car(tire: 4) -var b = Bike(tire: 2) -echo testVehicle b, c \ No newline at end of file diff --git a/tests/typerel/t4799_6.nim b/tests/typerel/t4799_6.nim deleted file mode 100644 index cfd399a6e0..0000000000 --- a/tests/typerel/t4799_6.nim +++ /dev/null @@ -1,20 +0,0 @@ -discard """ - outputsub: '''ObjectAssignmentError''' - exitcode: "1" -""" - -type - Vehicle[T] = object of RootObj - tire: T - Car[T] = object of Vehicle[T] - Bike[T] = object of Vehicle[T] - -proc testVehicle[T](x: varargs[Vehicle[T]]): string = - result = "" - for c in x: - result.add $c.tire - -var v = Vehicle[int](tire: 3) -var c = Car[int](tire: 4) -var b = Bike[int](tire: 2) -echo testVehicle([b, c, v]) \ No newline at end of file diff --git a/tests/typerel/t4799_7.nim b/tests/typerel/t4799_7.nim deleted file mode 100644 index 784eee8fc1..0000000000 --- a/tests/typerel/t4799_7.nim +++ /dev/null @@ -1,20 +0,0 @@ -discard """ - outputsub: '''ObjectAssignmentError''' - exitcode: "1" -""" - -type - Vehicle = object of RootObj - tire: int - Car = object of Vehicle - Bike = object of Vehicle - -proc testVehicle(x: varargs[Vehicle]): string = - result = "" - for c in x: - result.add $c.tire - -var v = Vehicle(tire: 3) -var c = Car(tire: 4) -var b = Bike(tire: 2) -echo testVehicle([b, c, v]) \ No newline at end of file From 4262a85653e22e430824c92db35c5ee3bcecf954 Mon Sep 17 00:00:00 2001 From: andri lim Date: Wed, 6 Jun 2018 22:29:31 +0700 Subject: [PATCH 4/4] fixed wrong test --- tests/typerel/t4799.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/typerel/t4799.nim b/tests/typerel/t4799.nim index 89312950fe..0758934763 100644 --- a/tests/typerel/t4799.nim +++ b/tests/typerel/t4799.nim @@ -187,7 +187,7 @@ block test_t4799_7: var b = Bike[int](tire: 2) reject: - echo testVehicle b, c, v + echo testVehicle(b, c, v) block test_t4799_8: type @@ -206,7 +206,7 @@ block test_t4799_8: var b = Bike(tire: 2) reject: - echo testVehicle b, c, v + echo testVehicle(b, c, v) type PGVehicle[T] = ptr object of RootObj @@ -223,7 +223,7 @@ var pgc = PGCar[int](tire: 4) var pgb = PGBike[int](tire: 2) reject: - echo testVehicle pgb, pgc + echo testVehicle(pgb, pgc) type RVehicle = ptr object of RootObj @@ -240,6 +240,6 @@ var rc = RCar(tire: 4) var rb = RBike(tire: 2) reject: - echo testVehicle rb, rc + echo testVehicle(rb, rc) echo "OK"