-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix #16736 assign closure proc to const should be CT error #20408
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
Conversation
|
CI fails cause by #14340 related test case , if this PR accepted , should remove that test case. proc opl3EnvelopeCalcSin0() = discard
type EnvelopeSinfunc = proc()
# const EnvelopeCalcSin0 = opl3EnvelopeCalcSin0 # ok
const EnvelopeCalcSin0: EnvelopeSinfunc = opl3EnvelopeCalcSin0 # was bug
const envelopeSin = [EnvelopeCalcSin0]
var a = 0
envelopeSin[a]() |
|
@bung87 You basically cause the error: And why do you think setting to a Like:
|
|
Bung pinged me in realtime chat I assume to respond
Not only that but presently the following errors: const a = proc() {.closure.} = echo "Hello"
a()
Since it's attempting to evaluate
Another example to explain how odd it is of a concept to me: proc makeMyClosure(r: ref int): proc() =
result = proc() =
inc r[]
echo r[]
var myRef {.compileTime.} = new int # This makes a reference in VM since it needs to be accessible at CT, but we can make a closure to capture it.
const a = makeMyClosure(myRef)
let b = a
b() |
|
Thanks beef's response, am not a native english speaker and not capble to explain this, so I pinged beef, as we discussed yesterday about this. now am pretty sure this should be CT error. |
|
Patch the existing |
|
Why shouldn't const be allowed to be a proc? It makes proc's less of first-class citizens in the language, which prevents some code and generic constructs, as well as renamed function pointers and other use cases |
today's news is it is planed to support, but for now it may causes users mis-use, which we dont like to see. |
|
Example use case: status-im/nim-chronos#319 |
|
since chronos used as a real use case, that can't be patched in a easy way, I decide partially support it or wait real const closure implementation. |
Can't we find a way to only allow calling non-closures converted to a closure type at runtime? i.e. if the closure environment is nil, or whatever that would correspond to for the compile time VM (I'm guessing all procvars at compile time are stored as symbols, so we would check if the symbol type is a closure). |
fix #16736
fix #16737