diff options
| author | metagn <metagngn@gmail.com> | 2024-09-18 20:27:09 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-18 19:27:09 +0200 |
| commit | 0c3573e4a0628bbaa8b09dcd854bdc2702948bbc (patch) | |
| tree | 0395872790437f6eebf2c52a8401fbbb22254d33 /tests | |
| parent | 79b17b7c05f66a032949135f4d5a4a62ab9c36a0 (diff) | |
| download | Nim-0c3573e4a0628bbaa8b09dcd854bdc2702948bbc.tar.gz | |
make `genericsOpenSym` work at instantiation time, new behavior in `openSym` (#24111)
alternative to #24101
#23892 changed the opensym experimental switch so that it has to be
enabled in the context of the generic/template declarations capturing
the symbols, not the context of the instantiation of the
generics/templates. This was to be in line with where the compiler gives
the warnings and changes behavior in a potentially breaking way.
However `results` [depends on the old
behavior](https://github.com/arnetheduck/nim-results/blob/71d404b314479a6205bfd050f4fe5fe49cdafc69/results.nim#L1428),
so that the callers of the macros provided by results always take
advantage of the opensym behavior. To accomodate this, we change the
behavior of the old experimental option that `results` uses,
`genericsOpenSym`, so that ignores the information of whether or not
symbols are intentionally opened and always gives the opensym behavior
as long as it's enabled at instantiation time. This should keep
`results` working as is. However this differs from the normal opensym
switch in that it doesn't generate `nnkOpenSym`.
Before it was just a generics-only version of `openSym` along with
`templateOpenSym` which was only for templates. So `templateOpenSym` is
removed along with this change, but no one appears to have used it.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/generics/mopensymimport2.nim | 2 | ||||
| -rw-r--r-- | tests/generics/tmacroinjectedsym.nim | 2 | ||||
| -rw-r--r-- | tests/template/topensym.nim | 2 | ||||
| -rw-r--r-- | tests/template/topensymoverride.nim | 39 |
4 files changed, 42 insertions, 3 deletions
diff --git a/tests/generics/mopensymimport2.nim b/tests/generics/mopensymimport2.nim index 1e1cda301..c17aafd00 100644 --- a/tests/generics/mopensymimport2.nim +++ b/tests/generics/mopensymimport2.nim @@ -1,4 +1,4 @@ -{.experimental: "genericsOpenSym".} +{.experimental: "openSym".} import mopensymimport1 diff --git a/tests/generics/tmacroinjectedsym.nim b/tests/generics/tmacroinjectedsym.nim index e3bc1be1e..985e415f2 100644 --- a/tests/generics/tmacroinjectedsym.nim +++ b/tests/generics/tmacroinjectedsym.nim @@ -1,4 +1,4 @@ -{.experimental: "genericsOpenSym".} +{.experimental: "openSym".} block: # issue #22605, normal call syntax const error = "bad" diff --git a/tests/template/topensym.nim b/tests/template/topensym.nim index 9393e1971..2f930407b 100644 --- a/tests/template/topensym.nim +++ b/tests/template/topensym.nim @@ -1,4 +1,4 @@ -{.experimental: "templateOpenSym".} +{.experimental: "openSym".} block: # issue #24002 type Result[T, E] = object diff --git a/tests/template/topensymoverride.nim b/tests/template/topensymoverride.nim new file mode 100644 index 000000000..3d4bb59f1 --- /dev/null +++ b/tests/template/topensymoverride.nim @@ -0,0 +1,39 @@ +discard """ + matrix: "--skipParentCfg --filenames:legacyRelProj" +""" + +const value = "captured" +template fooOld(x: int, body: untyped): untyped = + let value {.inject.} = "injected" + body +template foo(x: int, body: untyped): untyped = + let value {.inject.} = "injected" + {.push experimental: "genericsOpenSym".} + body + {.pop.} + +proc old[T](): string = + fooOld(123): + return value +doAssert old[int]() == "captured" + +template oldTempl(): string = + block: + var res: string + fooOld(123): + res = value + res +doAssert oldTempl() == "captured" + +proc bar[T](): string = + foo(123): + return value +doAssert bar[int]() == "injected" + +template barTempl(): string = + block: + var res: string + foo(123): + res = value + res +doAssert barTempl() == "injected" |