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
Closed

Can't declare a mixin. #11237

deech opened this issue May 12, 2019 · 2 comments

Comments

@deech
Copy link
Contributor

deech 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
Copy link
Contributor Author

deech 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
Copy link
Collaborator

mratsim commented May 13, 2019

Seems like a simplified duplicate of #7385

@Araq Araq closed this as completed in f84293a May 13, 2019
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

2 participants