Visitar URL original
Fix nullable parameter code generation by ninjapanzer · Pull Request #191 · hugopl/gi-crystal · GitHub
Skip to content

Fix nullable parameter code generation - #191

Open
ninjapanzer wants to merge 2 commits into
hugopl:mainfrom
ninjapanzer:main
Open

ninjapanzer wants to merge 2 commits into
hugopl:mainfrom
ninjapanzer:main

Conversation

@ninjapanzer

Copy link
Copy Markdown

What

When generating bindings for functions with nullable non-array parameters, gi-crystal produces invalid Crystal code.

  • Added regression test that verifies generated code uses _nullable pattern. Existing core tests guards against _nullable parameters_ from /spec/basic_spec.cr guard against this bug so this new spec if for regression coverage.
  • The sum_nullable test has an array_length annotation, so ArrayLengthArgPlan handles it using .try(&.size) instead of generate_null_guard. The bug only triggers for nullable non-array parameters.

Related Issues

Fixes the "can't use variable name inside assignment to variable" error
that occurs when generating bindings for functions with nullable
parameters.
Verifies the generator produces `_nullable = if nullable.nil?` instead
of the broken `nullable = if nullable.nil?` pattern that Crystal rejects
with "can't use variable name inside assignment".
@magynhard

Copy link
Copy Markdown

I had the same problem and used this PR to fix it. I would appreciate it, if this PR is going to be in a future official release soon.

@hugopl

hugopl commented Sep 9, 2026

Copy link
Copy Markdown
Owner

believe me, I just saw this PR today, I'll review it next days, thanks!

@ninjapanzer

Copy link
Copy Markdown
Author

@hugopl bump :)

Happy Wednesday!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error compiling harf_buzz - can't use variable name 'glyphs_before' inside assignment to variable 'glyphs_before' syntax error in './gsk-4.0/path_point.cr:122:13': can't use variable name 'center' inside assignment to variable 'center'

3 participants