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

recursive function with static argument changes argument type from enum to int #9520

Closed
cooldome opened this issue Oct 26, 2018 · 2 comments
Closed

Comments

@cooldome
Copy link
Member

The output is not correct and weirdly enough only recursive functions are affected.

Example

type
  MyEnum = enum
    Val1, Val2

proc myproc(a: static[MyEnum], b: int) =
  if b < 0:
    myproc(a, -b)

  echo $a

myproc(Val1, -10)

Current Output

0
0

Expected Output

Val1
Val1

Interestingly that if you remove unrelated recursive call then you will get expected output: Val1.

@krux02
Copy link
Contributor

krux02 commented Oct 26, 2018

an enum is internally represented as an integer. A static arguments instanciates the function for each argument value. My guess it that during this instantiation the information that a is actually an enum is lost.

@krux02 krux02 changed the title Bug with recursive functions and static types recursive function with static argument changes argument type from enum to int Oct 26, 2018
@mratsim
Copy link
Collaborator

mratsim commented Oct 26, 2018

Related to this I suppose: #7375

cooldome added a commit that referenced this issue Nov 5, 2020
@Araq Araq closed this as completed in cdd459d Nov 6, 2020
narimiran pushed a commit that referenced this issue Nov 9, 2020
* close #9679

* close #7546

* close #9520

* close #6177

(cherry picked from commit cdd459d)
PMunch pushed a commit to PMunch/Nim that referenced this issue Jan 6, 2021
mildred pushed a commit to mildred/Nim that referenced this issue Jan 11, 2021
irdassis pushed a commit to irdassis/Nim that referenced this issue Mar 16, 2021
ardek66 pushed a commit to ardek66/Nim that referenced this issue Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants