* fixes #10203
* make typredef test green again
* fixes the regressions differently
This commit is contained in:
Andreas Rumpf
2019-01-15 10:15:27 +01:00
committed by GitHub
parent 06a8b48811
commit 05c52ff34f
3 changed files with 34 additions and 16 deletions

View File

@@ -1318,7 +1318,19 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
if tx != result and tx.kind == tyObject and tx.sons[0] != nil:
semObjectTypeForInheritedGenericInst(c, n, tx)
proc maybeAliasType(c: PContext; typeExpr, prev: PType): PType
proc maybeAliasType(c: PContext; typeExpr, prev: PType): PType =
if typeExpr.kind in {tyObject, tyEnum, tyDistinct, tyForward} and prev != nil:
result = newTypeS(tyAlias, c)
result.rawAddSon typeExpr
result.sym = prev.sym
assignType(prev, result)
proc fixupTypeOf(c: PContext, prev: PType, typExpr: PNode) =
if prev != nil:
let result = newTypeS(tyAlias, c)
result.rawAddSon typExpr.typ
result.sym = prev.sym
assignType(prev, result)
proc semTypeExpr(c: PContext, n: PNode; prev: PType): PType =
var n = semExprWithType(c, n, {efDetermineType})
@@ -1422,20 +1434,6 @@ proc semProcTypeWithScope(c: PContext, n: PNode,
when useEffectSystem: setEffectsForProcType(c.graph, result, n.sons[1])
closeScope(c)
proc maybeAliasType(c: PContext; typeExpr, prev: PType): PType =
if typeExpr.kind in {tyObject, tyEnum, tyDistinct} and prev != nil:
result = newTypeS(tyAlias, c)
result.rawAddSon typeExpr
result.sym = prev.sym
assignType(prev, result)
proc fixupTypeOf(c: PContext, prev: PType, typExpr: PNode) =
if prev != nil:
let result = newTypeS(tyAlias, c)
result.rawAddSon typExpr.typ
result.sym = prev.sym
assignType(prev, result)
proc symFromExpectedTypeNode(c: PContext, n: PNode): PSym =
if n.kind == nkType:
result = symFromType(c, n.typ, n.info)

View File

@@ -432,7 +432,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
sfAnon notin t.sym.flags:
if t.kind == tyInt and isIntLit(t):
result = t.sym.name.s & " literal(" & $t.n.intVal & ")"
elif t.kind == tyAlias:
elif t.kind == tyAlias and t.sons[0].kind != tyAlias:
result = typeToString(t.sons[0])
elif prefer in {preferName, preferTypeName} or t.sym.owner.isNil:
result = t.sym.name.s

View File

@@ -17,3 +17,23 @@ suite "object basic methods":
check($obj == "(foo: 1)")
test "it should test equality based on fields":
check(makeObj(1) == makeObj(1))
# bug #10203
type
TMyObj = TYourObj
TYourObj = object of RootObj
x, y: int
proc init: TYourObj =
result.x = 0
result.y = -1
proc f(x: var TYourObj) =
discard
var m: TMyObj = init()
f(m)
var a: TYourObj = m
var b: TMyObj = a