Skip to content

Commit

Permalink
Revert "make default values typed in proc AST same as param sym AST" (#…
Browse files Browse the repository at this point in the history
…24191)

Reverts #24184, reopens #12942, reopens #19118

#24184 seems to have caused a regression in
https://github.com/c-blake/thes and
https://github.com/c-blake/bu/blob/main/rp.nim#L84 reproducible with
`git clone https://github.com/c-blake/cligen; git clone
https://github.com/c-blake/thes; cd thes; nim c -p=../cligen thes`.
Changing the `const` to `let` makes it compile.

A minimization that is probably the same issue is:

```nim
const a: seq[string] = @[]

proc foo(x = a) =
  echo typeof(x)
  echo x

import macros

macro resemFoo() =
  result = getImpl(bindSym"foo")

block:
  resemFoo() # Error: cannot infer the type of parameter 'x'
```

This should be a regression test in a future reimplementation of #24184.
  • Loading branch information
metagn authored Sep 27, 2024
1 parent 2cdc0e9 commit 821d080
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 54 deletions.
2 changes: 0 additions & 2 deletions compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1409,8 +1409,6 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
elif typ.kind == tyStatic:
def = semConstExpr(c, def)
def = fitNode(c, typ, def, def.info)
# keep proc AST updated
a[^1] = def

if not hasType and not hasDefault:
if isType: localError(c.config, a.info, "':' expected")
Expand Down
4 changes: 2 additions & 2 deletions tests/errmsgs/tunknown_named_parameter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ func rsplit(s: string; sep: string; maxsplit: int = -1): seq[string]
first type mismatch at position: 2
required type for sep: string
but expression '{':'}' is of type: set[char]
func rsplit(s: string; seps: set[char] = {' ', '\t', '\v', '\r', '\n', '\f'};
maxsplit: int = -1): seq[string]
func rsplit(s: string; seps: set[char] = Whitespace; maxsplit: int = -1): seq[
string]
first type mismatch at position: 3
unknown named parameter: maxsplits
Expand Down
50 changes: 0 additions & 50 deletions tests/proc/tdefaultvalueprocast.nim

This file was deleted.

0 comments on commit 821d080

Please sign in to comment.