diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index aa0489cd22..9f61fe6f26 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -578,7 +578,14 @@ proc isOpImpl(c: PContext, n: PNode, flags: TExprFlags): PNode = if efExplain in flags: m.diagnostics = @[] m.diagnosticsEnabled = true - res = typeRel(m, t2, t1) >= isSubtype # isNone + let rel = typeRel(m, t2, t1) + res = rel >= isSubtype # isNone + if res and rel == isEqual and + not compareTypes(t1, t2, + flags = {ExactTypeDescValues, + PickyCAliases, + PickyBackendAliases}): + res = false # `res = sameType(t1, t2)` would be wrong, e.g. for `int is (int|float)` result = newIntNode(nkIntLit, ord(res)) diff --git a/compiler/types.nim b/compiler/types.nim index 0b1388da0a..51596e0a09 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -897,7 +897,11 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool = c.flags = oldFlags if x == y: return true - let aliasSkipSet = maybeSkipRange({tyAlias, tyInferred}) + let aliasSkipSet = maybeSkipRange( + if PickyBackendAliases in c.flags: + {tyInferred} + else: + {tyAlias, tyInferred}) var a = skipTypes(x, aliasSkipSet) while a.kind == tyUserTypeClass and tfResolved in a.flags: a = skipTypes(a.last, aliasSkipSet) @@ -1070,8 +1074,8 @@ proc sameBackendTypeIgnoreRange*(x, y: PType): bool = result = sameTypeAux(x, y, c) proc sameBackendTypePickyAliases*(x, y: PType): bool = - let x = x.skipTypes(abstractVar) - let y = y.skipTypes(abstractVar) + let x = x.skipTypes({tyVar, tyLent, tySink, tyOwned}) + let y = y.skipTypes({tyVar, tyLent, tySink, tyOwned}) var c = initSameTypeClosure() c.flags.incl {IgnoreTupleFields, IgnoreRangeShallow, PickyCAliases, PickyBackendAliases} c.cmp = dcEqIgnoreDistinct