Skip to content

Conversation

@metagn
Copy link
Collaborator

@metagn metagn commented May 29, 2023

closes nim-lang/RFCs#229

Preview define for now because a package broke.

There is also cstring to pointer conversion which was not removed in #20761 or mentioned in #13790, however this is also documented so I didn't touch it for now.

@metagn metagn changed the title test proc not converting to pointer test proc and cstring not converting to pointer May 29, 2023
@metagn metagn changed the title test proc and cstring not converting to pointer test proc not converting to pointer May 29, 2023
@metagn metagn changed the title test proc not converting to pointer make proc not implicitly convert to pointer May 29, 2023
@metagn metagn changed the title make proc not implicitly convert to pointer make proc not implicitly convert to pointer with a preview define May 29, 2023
@metagn metagn marked this pull request as ready for review May 29, 2023 10:51
@Araq
Copy link
Member

Araq commented May 29, 2023

-1 from me, we allow var p: pointer = addr(x) too, so we should allow var p: pointer = someProc.

@juancarlospaco
Copy link
Collaborator

Maybe it can be an optional Hint or Warning ?. 🙂

@Araq
Copy link
Member

Araq commented May 29, 2023

Why? Nobody reported any bugs due to this behavior.

@metagn
Copy link
Collaborator Author

metagn commented May 29, 2023

The problem mentioned in nim-lang/RFCs#229 is that the conversion can happen implicitly in proc parameters.

# defined in system:
proc `==`(a, b: pointer)
proc `==`[T: proc](a, b: proc)

proc foo(a: int) = discard
proc bar(a: float) = discard

echo foo == bar # does pointer(foo) == pointer(bar)

This conversion is safe but maybe not always wanted. I don't know which mechanism makes it so this kind of "implicit" conversion doesn't work but var p: pointer does (don't know if this makes sense either). ptr is different because pointer is basically ptr any.

@Araq Araq merged commit 20446b4 into nim-lang:devel May 30, 2023
@github-actions
Copy link
Contributor

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 20446b4

Hint: mm: orc; opt: speed; options: -d:release
167601 lines; 8.269s; 612.996MiB peakmem

bung87 pushed a commit to bung87/Nim that referenced this pull request Jul 29, 2023
…nim-lang#21953)

* test `proc` not converting to `pointer`

* ignore define for now to test

* remove cstring

* fixes, changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFC: deprecate implicit conversions from procvar => pointer and ptr T => pointer; enable function merging

3 participants