Fix Slice.literal for multiple calls with identical signature#15009
Conversation
|
I don't like going from explicit This primitive basically expands the call into a different call (and an implicit const declaration as side effect). This seems more similar to a |
|
Besides, if we eventually standardize a distinct syntactic form for those literals, there has to be some extra compiler integration anyway. |
straight-shoota
left a comment
There was a problem hiding this comment.
I'm not sure happy with this change, as commented above. But it's good as a bug fix and hopefully will be a temporary solution.
Fixes #14572.
The usual type inference mechanism for method calls calculates the return type exactly once for each combination of call signature. Therefore, if two slice literals have the same element type, arity, and argument types, only the first one gets seen by
Crystal::MainVisitor#visit(Crystal::Primitive), thus subsequent literals reach the codegen phase without being expanded. This PR makes the expansion bypass the usual mechanism and happen much earlier, right after checking for.newof lib types.A consequence is that
Sliceis now a built-in type and theSlice.literaldeclaration is no longer necessary; the@[Primitive(:slice_literal)]is a placeholder and does not drive the actual expansion.