fixes #21377; fixes @[] and {} type inference as returns in generics (#21475)

* fixes `@[]` type inference in generics

* add issue links

* fixes macros and iterators

* refactor

* add one more test
This commit is contained in:
ringabout 2023-03-06 22:30:22 +08:00 • committed by GitHub
commit 64a0355f3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 5 deletions

View file

@ -526,7 +526,7 @@ proc checkDefault(c: PContext, n: PNode): PNode =
message(c.config, n.info, warnUnsafeDefault, typeToString(constructed))
proc magicsAfterOverloadResolution(c: PContext, n: PNode,
flags: TExprFlags): PNode =
flags: TExprFlags; expectedType: PType = nil): PNode =
## This is the preferred code point to implement magics.
## ``c`` the current module, a symbol table to a very good approximation
## ``n`` the ast like it would be passed to a real macro
@ -635,5 +635,9 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
result = n
of mPrivateAccess:
result = semPrivateAccess(c, n)
of mArrToSeq:
result = n
if result.typ != nil and expectedType != nil and result.typ.kind == tySequence and expectedType.kind == tySequence and result.typ[0].kind == tyEmpty:
result.typ = expectedType # type inference for empty sequence # bug #21377
else:
result = n