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

Can't declare a mixin. #11237

Closed
deech opened this issue May 12, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@deech
Copy link
Contributor

commented May 12, 2019

Can't mixin a function.

Example

proc f() = 
  mixin a
  echo a()

proc a():string = "a"

echo f()

Current Output

testmixin.nim(2, 3) Error: invalid expression: mixin a1

Expected Output

a

Additional Information

$ nim -v
Nim Compiler Version 0.19.9 [Linux: amd64]
Compiled at 2019-05-12
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: a3e27ffa2c721b2ef3b0481d7db5c45039072050
active boot switches: -d:release
@deech

This comment has been minimized.

Copy link
Contributor Author

commented May 12, 2019

The issue is that for some reason a mixin only works inside a template or a generic proc, so this works:

template f() = 
  mixin a
  echo a()

proc a():string = "a"

f()

and so does this:

proc f[T]() =
  mixin a
  echo a()

proc a():string = "a"

f[int]()

If this is intended behavior it should be documented in the manual.

@mratsim

This comment has been minimized.

Copy link
Collaborator

commented May 13, 2019

Seems like a simplified duplicate of #7385

@Araq Araq closed this in f84293a May 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.