Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash with tyBuiltInTypeClass matching itself #24462

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1878,9 +1878,12 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
let target = f.genericHead
let targetKind = target.kind
var effectiveArgType = reduceToBase(a)
# the skipped child of tyBuiltInTypeClass can be structured differently,
# newConstraint constructs them with no children
let typeClassArg = effectiveArgType.kind == tyBuiltInTypeClass
effectiveArgType = effectiveArgType.skipTypes({tyBuiltInTypeClass})
if targetKind == effectiveArgType.kind:
if effectiveArgType.isEmptyContainer:
if not typeClassArg and effectiveArgType.isEmptyContainer:
return isNone
if targetKind == tyProc:
if target.flags * {tfIterator} != effectiveArgType.flags * {tfIterator}:
Expand Down
25 changes: 15 additions & 10 deletions tests/overload/tvartypeclass.nim
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# issue #13302
block: # issue #13302
proc foo(x: object): int = x.i*2
proc foo(x: var object) = x.i*=2
type Foo = object
i: int
let x = Foo(i: 3)
var y = Foo(i: 4)
doAssert foo(x) == 6
foo(y)
doAssert y.i == 8

proc foo(x: object): int = x.i*2
proc foo(x: var object) = x.i*=2
type Foo = object
i: int
let x = Foo(i: 3)
var y = Foo(i: 4)
doAssert foo(x) == 6
foo(y)
doAssert y.i == 8
block: # issue #24449
proc p(x: var seq)= discard
proc p(x: seq)= discard
var s : seq[int]
p(s)
Loading