Skip to content

Commit

Permalink
fix nim-lang#1385 type alias to tyor type in proc mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 committed Oct 18, 2022
1 parent 81087c9 commit 00a34e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,14 @@ proc isMagic(sym: PSym): bool =
let nPragmas = sym.ast[pragmasPos]
return hasPragma(nPragmas, wMagic)

proc maybeForkType(c: PContext, t: PType): PType =
if t.kind in {tyOr} and t.sym != nil:
result = newTypeS(t.kind, c)
newSons(result, t.len)
for i in 0..<t.len: result[i] = t[i]
else:
return t

proc semProcTypeNode(c: PContext, n, genericParams: PNode,
prev: PType, kind: TSymKind; isType=false): PType =
# for historical reasons (code grows) this is invoked for parameter
Expand Down Expand Up @@ -1352,6 +1360,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
else:
localError(c.config, a.info, "parameter '$1' requires a type" % arg.name.s)
typ = errorType(c)
typ = maybeForkType(c, typ)
let lifted = liftParamType(c, kind, genericParams, typ,
arg.name.s, arg.info)
let finalType = if lifted != nil: lifted else: typ.skipIntLit(c.idgen)
Expand Down
8 changes: 8 additions & 0 deletions tests/typerel/t1385.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type intorfloat = int or float

proc x(a: intorfloat; b: intorfloat): string =
result = $a & " " & $b

var c: float = 2.0
var d: int = 3
doAssert x(c, d) == "2.0 3"

0 comments on commit 00a34e4

Please sign in to comment.