summary refs log tree commit diff stats
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2024-09-27 16:34:09 +0300
committerGitHub <noreply@github.com>2024-09-27 15:34:09 +0200
commit821d0806feb3648ced5809a78b07581ea3bd7880 (patch)
treef8d6e773d730e0c390626df0c8db6835c8149f78
parent2cdc0e913fc6d7b3486b907de502faa508820c42 (diff)
downloadNim-821d0806feb3648ced5809a78b07581ea3bd7880.tar.gz
Revert "make default values typed in proc AST same as param sym AST" (#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.
-rw-r--r--compiler/semtypes.nim2
-rw-r--r--tests/errmsgs/tunknown_named_parameter.nim4
-rw-r--r--tests/proc/tdefaultvalueprocast.nim50
3 files changed, 2 insertions, 54 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 25ce73b51..857521232 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -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")
diff --git a/tests/errmsgs/tunknown_named_parameter.nim b/tests/errmsgs/tunknown_named_parameter.nim
index 9ec8bc9cd..d3dd6cd2d 100644
--- a/tests/errmsgs/tunknown_named_parameter.nim
+++ b/tests/errmsgs/tunknown_named_parameter.nim
@@ -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
 
diff --git a/tests/proc/tdefaultvalueprocast.nim b/tests/proc/tdefaultvalueprocast.nim
deleted file mode 100644
index cc5c4df25..000000000
--- a/tests/proc/tdefaultvalueprocast.nim
+++ /dev/null
@@ -1,50 +0,0 @@
-discard """
-  nimout: '''
-ProcDef
-  Sym "foo"
-  Empty
-  Empty
-  FormalParams
-    Empty
-    IdentDefs
-      Sym "x"
-      Empty
-      Call
-        Sym "none"
-        Sym "Natural"
-  Empty
-  Empty
-  DiscardStmt
-    Empty
-ProcDef
-  Sym "example"
-  Empty
-  Empty
-  FormalParams
-    Empty
-    IdentDefs
-      Sym "a"
-      Empty
-      Sym "thing"
-  Empty
-  Empty
-  DiscardStmt
-    TupleConstr
-      Sym "a"
-      Sym "thing"
-'''
-"""
-
-import options, macros
-
-macro typedTree(n: typed): untyped =
-  result = n
-  echo treeRepr n
-
-# issue #19118
-proc foo(x = none(Natural)) {.typedTree.} = discard
-
-# issue #12942
-var thing = 2
-proc example(a = thing) {.typedTree.} =
-  discard (a, thing)