-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
don't use previous bindings of
auto
for routine return types (#23207)
fixes #23200, fixes #18866 #21065 made it so `auto` proc return types remained as `tyAnything` and not turned to `tyUntyped`. This had the side effect that anything previously bound to `tyAnything` in the proc type match was then bound to the proc return type, which is wrong since we don't know the proc return type even if we know the expected parameter types (`tyUntyped` also [does not care about its previous bindings in `typeRel`](https://github.com/nim-lang/Nim/blob/ab4278d2179639f19967431a7aa1be858046f7a7/compiler/sigmatch.nim#L1059-L1061) maybe for this reason). Now we mark `tyAnything` return types for routines as `tfRetType` [as done for other meta return types](https://github.com/nim-lang/Nim/blob/18b5fb256d4647efa6a64df451d37129d36e96f3/compiler/semtypes.nim#L1451), and ignore bindings to `tyAnything` + `tfRetType` types in `semtypinst`. On top of this, we reset the type relation in `paramTypesMatch` only after creating the instantiation (instead of trusting `isInferred`/`isInferredConvertible` before creating the instantiation), using the same mechanism that `isBothMetaConvertible` uses. This fixes the issues as well as making the disabled t15386_2 test introduced in #21065 work. As seen in the changes for the other tests, the error messages give an obscure `proc (a: GenericParam): auto` now, but it does give the correct error that the overload doesn't match instead of matching the overload pre-emptively and expecting a specific return type. tsugar had to be changed due to #16906, which is the problem where `void` is not inferred in the case where `result` was never touched.
- Loading branch information
Showing
10 changed files
with
91 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import std/[sugar, sequtils] | ||
|
||
block: # issue #23200 | ||
proc dosomething(iter: int -> (iterator: int)) = | ||
discard | ||
proc dosomething(iter: int -> seq[int]) = | ||
discard | ||
proc makeSeq(x: int): seq[int] = | ||
@[x] | ||
# Works fine with 1.6.12 and 1.6.14 | ||
dosomething(makeSeq) | ||
# Works with 1.6.12, fails with 1.6.14 | ||
dosomething((y) => makeSeq(y)) | ||
dosomething(proc (y: auto): auto = makeSeq(y)) | ||
proc foo(y: auto): auto = makeSeq(y) | ||
dosomething(foo) | ||
|
||
block: # issue #18866 | ||
proc somefn[T](list: openarray[T], op: proc (v: T): float) = | ||
discard op(list[0]) | ||
|
||
type TimeD = object | ||
year: Natural | ||
month: 1..12 | ||
day: 1..31 | ||
|
||
doAssert not compiles(@[TimeD()].somefn(proc (v: auto): auto = | ||
v | ||
)) | ||
@[TimeD()].somefn(proc (v: auto): auto = | ||
v.year.float | ||
) | ||
proc foo(v: auto): auto = v | ||
doAssert not compiles(@[TimeD()].somefn(foo)) | ||
proc bar(v: auto): auto = v.year.float | ||
@[TimeD()].somefn(bar) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
|
||
discard """ | ||
action: "compile" | ||
disabled: true | ||
""" | ||
import std/sugar | ||
|
||
type Tensor[T] = object | ||
|