diff options
author | metagn <metagngn@gmail.com> | 2024-09-18 18:37:18 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-18 17:37:18 +0200 |
commit | 1660ddf98a6b6fbd8f05b58bbc540bc57523b31c (patch) | |
tree | dfda6350da1aee487a9d7eba1754b87ebd33edd5 /compiler | |
parent | c759d7abd1b4181fb4931bc95148beac3051bf91 (diff) | |
download | Nim-1660ddf98a6b6fbd8f05b58bbc540bc57523b31c.tar.gz |
make `var`/pointer types not match if base type has to be converted (#24130)
split again from #24038, fixes https://github.com/status-im/nimbus-eth2/pull/6554#issuecomment-2354977102 `var`/pointer types are no longer implicitly convertible to each other if their element types either: * require an int conversion or another conversion operation as long as it's not to `openarray`, * are subtypes with pointer indirection, Previously any conversion below a subrange match would match if the element type wasn't a pointer type, then it would error later in `analyseIfAddressTaken`. Different from #24038 in that the preview define that made subrange matches also fail to match is removed for a simpler diff so that it can be backported.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/sigmatch.nim | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index a48e79b7c..873eefd76 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1125,9 +1125,21 @@ proc inferStaticsInRange(c: var TCandidate, doInferStatic(lowerBound, getInt(upperBound) + 1 - lengthOrd(c.c.config, concrete)) template subtypeCheck() = - if result <= isSubrange and f.last.skipTypes(abstractInst).kind in { - tyRef, tyPtr, tyVar, tyLent, tyOwned}: + case result + of isIntConv: result = isNone + of isSubrange: + discard # XXX should be isNone with preview define, warnings + of isConvertible: + if f.last.skipTypes(abstractInst).kind != tyOpenArray: + # exclude var openarray which compiler supports + result = isNone + of isSubtype: + if f.last.skipTypes(abstractInst).kind in { + tyRef, tyPtr, tyVar, tyLent, tyOwned}: + # compiler can't handle subtype conversions with pointer indirection + result = isNone + else: discard proc isCovariantPtr(c: var TCandidate, f, a: PType): bool = # this proc is always called for a pair of matching types |