For example:
@[Primitive(:symbol_to_s)]
def method
end
method
results in:
Error in line 4: instantiating 'method()'
in line 2: BUG: unhandled primitive in MainVisitor: symbol_to_s
I'm sure you can attach any of the primitives listed here: primitives.cr:16
and you would get a bug.
The primitive symbol doesn't even have to exist, this will fail with the above error too:
@[Primitive(:nonexistent)]
def method
end
method
But not all fail with the error above. For example this:
@[Primitive(:pointer_set)]
def method
end
method
instead results in:
cast from Crystal::Program to Crystal::PointerInstanceType failed, at /build/crystal/src/crystal-0.27.0/src/compiler/crystal/semantic/main_visitor.cr:2419:15:2419 (TypeCastError)
from ???
from ???
from ???
from ???
from ???
from ???
from ???
from ???
from ???
from ???
from ???
from ???
from ???
from ???
from ???
from __crystal_main
from main
from __libc_start_main
from _start
from ???
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues
And
@[Primitive(:argc)]
def method
end
method
results in
BUG: unhandled primitive in codegen: argc (Exception)
from ???
from ???
from ???
from ???
from ???
from ???
from ???
from ???
from ???
from ???
from __crystal_main
from main
from __libc_start_main
from _start
from ???
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues
There might be more annotations that cause bugs when attaching them to normal methods.
This is expected, these methods need a receiver to work. What's the usecase here?
There's no usecase. I simply wanted to report these messages because you should never get those "BUG" messages. They should be changed to proper helpful error messages.
@[Primitive]
is compiler internal. You should never be using them yourself. I vote to close.
Yes, let's close this. Primitive
has no other use than for us, compiler writers, to implement the basic stuff. It's not even documented in the docs.
Maybe we could document a list of reserved annotations?
Maybe we could make it Crystal::Primitive
, then it's by definition reserved.
Most helpful comment
Maybe we could make it
Crystal::Primitive
, then it's by definition reserved.