mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-28 09:31:38 +00:00
* fix #15836 proc arg return type auto unexpectly match proc with concrete type * fix #16244 * add test case for #12869
This commit is contained in:
11
tests/types/t15836.nim
Normal file
11
tests/types/t15836.nim
Normal file
@@ -0,0 +1,11 @@
|
||||
discard """
|
||||
errormsg: "type mismatch: got <string> but expected 'int'"
|
||||
line: 11
|
||||
"""
|
||||
|
||||
proc takesProc[T](x: T, f: proc(x: T): int) =
|
||||
echo f(x) + 2
|
||||
|
||||
takesProc(1, proc (a: int): int = 2) # ok, prints 4
|
||||
takesProc(1, proc (a: auto): auto = 2) # ok, prints 4
|
||||
takesProc(1, proc (a: auto): auto = "uh uh") # prints garbage
|
||||
26
tests/types/t15836_2.nim
Normal file
26
tests/types/t15836_2.nim
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
discard """
|
||||
action: "compile"
|
||||
disabled: true
|
||||
"""
|
||||
import std/sugar
|
||||
|
||||
type Tensor[T] = object
|
||||
x: T
|
||||
|
||||
proc numerical_gradient*[T](input: T, f: (proc(x: T): T), h = T(1e-5)): T {.inline.} =
|
||||
result = default(T)
|
||||
|
||||
proc numerical_gradient*[T](input: Tensor[T], f: (proc(x: Tensor[T]): T), h = T(1e-5)): Tensor[T] {.noinit.} =
|
||||
result = default(Tensor[T])
|
||||
|
||||
proc conv2d*[T](input: Tensor[T]): Tensor[T] {.inline.} =
|
||||
result = default(Tensor[T])
|
||||
|
||||
proc sum*[T](arg: Tensor[T]): T = default(T)
|
||||
|
||||
proc sum*[T](arg: Tensor[T], axis: int): Tensor[T] {.noinit.} = default(Tensor[T])
|
||||
|
||||
let dinput = Tensor[int](x: 1)
|
||||
let target_grad_input = dinput.numerical_gradient(
|
||||
x => conv2d(x).sum())
|
||||
Reference in New Issue
Block a user