fixes #681
This commit is contained in:
parent
2dcbc6493a
commit
b3d759ca6d
2 changed files with 32 additions and 2 deletions
|
|
@ -90,6 +90,24 @@ proc commonType*(x, y: PType): PType =
|
||||||
let idx = ord(b.kind in {tyArray, tyArrayConstr})
|
let idx = ord(b.kind in {tyArray, tyArrayConstr})
|
||||||
if a.sons[idx].kind == tyEmpty: return y
|
if a.sons[idx].kind == tyEmpty: return y
|
||||||
#elif b.sons[idx].kind == tyEmpty: return x
|
#elif b.sons[idx].kind == tyEmpty: return x
|
||||||
|
elif a.kind == tyRange and b.kind == tyRange:
|
||||||
|
# consider: (range[0..3], range[0..4]) here. We should make that
|
||||||
|
# range[0..4]. But then why is (range[0..4], 6) not range[0..6]?
|
||||||
|
# But then why is (2,4) not range[2..4]? But I think this would break
|
||||||
|
# too much code. So ... it's the same range or the base type. This means
|
||||||
|
# type(if b: 0 else 1) == int and not range[0..1]. For now. In the long
|
||||||
|
# run people expect ranges to work properly within a tuple.
|
||||||
|
if not sameType(a, b):
|
||||||
|
result = skipTypes(a, {tyRange}).skipIntLit
|
||||||
|
when false:
|
||||||
|
if a.kind != tyRange and b.kind == tyRange:
|
||||||
|
# XXX This really needs a better solution, but a proper fix now breaks
|
||||||
|
# code.
|
||||||
|
result = a #.skipIntLit
|
||||||
|
elif a.kind == tyRange and b.kind != tyRange:
|
||||||
|
result = b #.skipIntLit
|
||||||
|
elif a.kind in IntegralTypes and a.n != nil:
|
||||||
|
result = a #.skipIntLit
|
||||||
else:
|
else:
|
||||||
var k = tyNone
|
var k = tyNone
|
||||||
if a.kind in {tyRef, tyPtr}:
|
if a.kind in {tyRef, tyPtr}:
|
||||||
|
|
@ -103,7 +121,7 @@ proc commonType*(x, y: PType): PType =
|
||||||
if result.isNil: return x
|
if result.isNil: return x
|
||||||
if k != tyNone:
|
if k != tyNone:
|
||||||
let r = result
|
let r = result
|
||||||
result = NewType(k, r.owner)
|
result = newType(k, r.owner)
|
||||||
result.addSonSkipIntLit(r)
|
result.addSonSkipIntLit(r)
|
||||||
|
|
||||||
proc isTopLevel(c: PContext): bool {.inline.} =
|
proc isTopLevel(c: PContext): bool {.inline.} =
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ discard """
|
||||||
file: "tlenopenarray.nim"
|
file: "tlenopenarray.nim"
|
||||||
output: '''1
|
output: '''1
|
||||||
0
|
0
|
||||||
Whopie'''
|
Whopie
|
||||||
|
12'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
echo len([1_000_000]) #OUT 1
|
echo len([1_000_000]) #OUT 1
|
||||||
|
|
@ -27,3 +28,14 @@ var w = TWidget(names: initQueue[string]())
|
||||||
add(w.names, "Whopie")
|
add(w.names, "Whopie")
|
||||||
|
|
||||||
for n in w.names: echo(n)
|
for n in w.names: echo(n)
|
||||||
|
|
||||||
|
# bug #681
|
||||||
|
|
||||||
|
type TSomeRange = object
|
||||||
|
hour: range[0..23]
|
||||||
|
|
||||||
|
var value: string
|
||||||
|
var val12 = TSomeRange(hour: 12)
|
||||||
|
|
||||||
|
value = $(if val12.hour > 12: val12.hour - 12 else: val12.hour)
|
||||||
|
echo value
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue