mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-30 16:45:38 +00:00
fixes #25796 This pull request addresses a subtle type-matching issue in the Nim compiler related to backend type compatibility, particularly for procedures returning `lent` types. It also adds new test cases to ensure correct handling of these scenarios. **Compiler type-checking fix:** * Updated `procParamTypeRel` in `compiler/sigmatch.nim` to skip wrappers like `tyVar`, `tyLent`, `tySink`, and `tyOwned` before comparing backend types, ensuring more accurate type equivalence checks for procedure parameters and return types. **Test coverage improvements:** * Added multiple blocks in `tests/proc/tproc.nim` to test procedure types returning `lent` objects, including cases with constants, variables, and union parameter types, verifying that the compiler now correctly handles these cases. --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
59 lines
979 B
Nim
59 lines
979 B
Nim
discard """
|
|
output: '''
|
|
Hello
|
|
1
|
|
'''
|
|
"""
|
|
|
|
|
|
block t8357:
|
|
type T = ref int
|
|
|
|
let r = new(string)
|
|
r[] = "Hello"
|
|
echo r[]
|
|
|
|
|
|
block t8683:
|
|
proc foo[T](bar: proc (x, y: T): int = system.cmp, baz: int) =
|
|
echo "1"
|
|
proc foo[T](bar: proc (x, y: T): int = system.cmp) =
|
|
echo "2"
|
|
|
|
foo[int](baz = 5)
|
|
|
|
|
|
block tnestprc:
|
|
proc Add3(x: int): int =
|
|
proc add(x, y: int): int {.noconv.} =
|
|
result = x + y
|
|
result = add(x, 3)
|
|
doAssert Add3(7) == 10
|
|
|
|
block:
|
|
type A = object
|
|
c: int
|
|
type H = proc(): lent A {.nimcall.}
|
|
const u = A(c: 0)
|
|
proc e(T: typedesc): lent A = u
|
|
proc y(T: typedesc): H =
|
|
proc(): lent A {.nimcall.} = T.e
|
|
discard y(int)
|
|
|
|
block:
|
|
type A = object
|
|
c: int
|
|
type H = proc(): lent A {.nimcall.}
|
|
let u = A(c: 0)
|
|
proc y(_: int | int): H =
|
|
proc(): lent A {.nimcall.} = u
|
|
discard y(0)
|
|
|
|
block:
|
|
type A = object
|
|
c: int
|
|
type H = proc(): lent A {.nimcall.}
|
|
let u = A()
|
|
let _: H = proc(): lent A {.nimcall.} = u
|
|
|