Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot add custom pragma to templates #18212

Closed
hamidb80 opened this issue Jun 7, 2021 · 6 comments · Fixed by #19406
Closed

cannot add custom pragma to templates #18212

hamidb80 opened this issue Jun 7, 2021 · 6 comments · Fixed by #19406

Comments

@hamidb80
Copy link
Contributor

hamidb80 commented Jun 7, 2021

Example

import macros

macro myCustomPragma(s: untyped): untyped =
  discard

template myTmplt(): untyped  {.myCustomPragma.}=
  discard

Current Output

Error: cannot attach a custom pragma to 'myTmplt'

Expected Output

compiles successfully

Additional Information

  • Nim compiler version: 1.4.8
  • OS: windows 10
@kaushalmodi
Copy link
Contributor

I can confirm this on Nim devel too.

From https://nim-lang.org/docs/manual.html#userminusdefined-pragmas-custom-annotations:

Custom pragmas can be used in all locations where ordinary pragmas can be specified. It is possible to annotate procs, templates, type and variable definitions, statements, etc.

But running below:

template myCustomPragma {.pragma.}

template myTmplt() {.myCustomPragma.} =
  discard

gives:

Error: cannot attach a custom pragma to 'myTmplt'

> nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-06-07
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 5bad022d58e21f0da455fbd7d421cd26a2b5c812
active boot switches: -d:release

@timotheecour
Copy link
Member

please check if duplicate of #15920, is so, close it

@hamidb80
Copy link
Contributor Author

hamidb80 commented Jun 8, 2021

related to timotheecour#129

@hamidb80 hamidb80 closed this as completed Jun 8, 2021
@Clyybber
Copy link
Contributor

Clyybber commented Jun 8, 2021

please check if duplicate of #15920, is so, close it

It isn't. template/macro pragma not working inside templates is different than not being able to attach a custom pragma to templates.

@Clyybber Clyybber reopened this Jun 8, 2021
@hamidb80
Copy link
Contributor Author

hamidb80 commented Jun 8, 2021

@Clyybber, it is the same as

related to timotheecour#129

@hamidb80 hamidb80 closed this as completed Jun 8, 2021
@timotheecour
Copy link
Member

related to timotheecour#129

that's not in nim repo though, it's my own issue tracker, so wouldn't count as duplicate

@timotheecour timotheecour reopened this Jun 8, 2021
metagn added a commit to metagn/Nim that referenced this issue Jan 17, 2022
fix nim-lang#15920, close nim-lang#18212, close nim-lang#14781, close nim-lang#6696,
close nim-lang/RFCs#220

Variable macro pragmas have been changed to
only take a unary section node.
They can now also be applied in sections with multiple variables,
as well as `const` sections. They also accept arguments.

Templates now support macro pragmas, mirroring other routine types.

Type and variable macro pragmas have been made experimental.
Symbols without parentheses instatiating nullary macros or templates
has also been documented in the experimental manual.

A check for a redefinition error based on the left hand side of variable
definitions when using variable macro pragmas was disabled.
This nerfs `byaddr` specifically, however this has been documented as
a consequence of the experimental features `byaddr` uses.

Given how simple these changes are I'm worried if I'm missing something.
Araq pushed a commit that referenced this issue Jan 20, 2022
* New/better macro pragmas, make some experimental

fix #15920, close #18212, close #14781, close #6696,
close nim-lang/RFCs#220

Variable macro pragmas have been changed to
only take a unary section node.
They can now also be applied in sections with multiple variables,
as well as `const` sections. They also accept arguments.

Templates now support macro pragmas, mirroring other routine types.

Type and variable macro pragmas have been made experimental.
Symbols without parentheses instatiating nullary macros or templates
has also been documented in the experimental manual.

A check for a redefinition error based on the left hand side of variable
definitions when using variable macro pragmas was disabled.
This nerfs `byaddr` specifically, however this has been documented as
a consequence of the experimental features `byaddr` uses.

Given how simple these changes are I'm worried if I'm missing something.

* accomodate compiler boot

* allow weird pragmas

* add test for #10994

* remove some control flow, try remove some logic
PMunch pushed a commit to PMunch/Nim that referenced this issue Mar 28, 2022
* New/better macro pragmas, make some experimental

fix nim-lang#15920, close nim-lang#18212, close nim-lang#14781, close nim-lang#6696,
close nim-lang/RFCs#220

Variable macro pragmas have been changed to
only take a unary section node.
They can now also be applied in sections with multiple variables,
as well as `const` sections. They also accept arguments.

Templates now support macro pragmas, mirroring other routine types.

Type and variable macro pragmas have been made experimental.
Symbols without parentheses instatiating nullary macros or templates
has also been documented in the experimental manual.

A check for a redefinition error based on the left hand side of variable
definitions when using variable macro pragmas was disabled.
This nerfs `byaddr` specifically, however this has been documented as
a consequence of the experimental features `byaddr` uses.

Given how simple these changes are I'm worried if I'm missing something.

* accomodate compiler boot

* allow weird pragmas

* add test for nim-lang#10994

* remove some control flow, try remove some logic
metagn added a commit to metagn/Nim that referenced this issue Apr 12, 2023
Araq pushed a commit that referenced this issue Apr 13, 2023
…elist (#21653)

* test not restricting custom pragma applied symbols

fixes #21652

* fix other test

* different patch

* fix tests

* actually test #18212 and other routines
capocasa pushed a commit to capocasa/Nim that referenced this issue May 15, 2023
…elist (nim-lang#21653)

* test not restricting custom pragma applied symbols

fixes nim-lang#21652

* fix other test

* different patch

* fix tests

* actually test nim-lang#18212 and other routines
capocasa pushed a commit to capocasa/Nim that referenced this issue May 16, 2023
…elist (nim-lang#21653)

* test not restricting custom pragma applied symbols

fixes nim-lang#21652

* fix other test

* different patch

* fix tests

* actually test nim-lang#18212 and other routines
bung87 pushed a commit to bung87/Nim that referenced this issue Jul 29, 2023
…elist (nim-lang#21653)

* test not restricting custom pragma applied symbols

fixes nim-lang#21652

* fix other test

* different patch

* fix tests

* actually test nim-lang#18212 and other routines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants