Skip to content

Fix type: Array + values: [...] coercing to the guessed element type instead of Array#2813

Merged
ericproulx merged 2 commits into
ruby-grape:masterfrom
schinery:array-param-regression
Jul 23, 2026
Merged

Fix type: Array + values: [...] coercing to the guessed element type instead of Array#2813
ericproulx merged 2 commits into
ruby-grape:masterfrom
schinery:array-param-regression

Conversation

@schinery

@schinery schinery commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

guess_coerce_type's result was overwriting @coerce_type in place, so type: Array + values: [...] param coerced at runtime using the guessed element type instead of Array — rejecting valid array input and duplicating the values error on invalid input.

The guessed type is now only used locally for the existing declaration-time validate_value_coercion check, never for coerce_options.

Fixes #2812.

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

@schinery
schinery force-pushed the array-param-regression branch from f3ea08a to c790357 Compare July 23, 2026 16:59
@schinery
schinery marked this pull request as ready for review July 23, 2026 17:04
@schinery schinery changed the title Fix type: Array + scalar values: coercing to the guessed element type instead of Array Fix type: Array + values: [...] coercing to the guessed element type instead of Array Jul 23, 2026
@schinery
schinery force-pushed the array-param-regression branch from c790357 to d0482a5 Compare July 23, 2026 17:06
@schinery
schinery force-pushed the array-param-regression branch from d0482a5 to 95a28b9 Compare July 23, 2026 17:07
@ericproulx

ericproulx commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

👋 @schinery I think the local guessed_coerce_type will always have the same result overtime since its value is based on previously initialized ivar and not any runtime values. Maybe we could add a @guessed_coerce_type in the initialize so we would have the original @coerce_type and the "guessed" one. Wdyt ?

@schinery

Copy link
Copy Markdown
Contributor Author

@ericproulx yeah good point. I've added @guessed_coerce_type into the initialize so it's computed once alongside @coerce_type rather than recomputed as a local inside validate! as well as an additional spec in 888cab8

Lemme know what you think.

@ericproulx

Copy link
Copy Markdown
Contributor

@ericproulx yeah good point. I've added @guessed_coerce_type into the initialize so it's computed once alongside @coerce_type rather than recomputed as a local inside validate! as well as an additional spec in 888cab8

Lemme know what you think.

Amazing!

@ericproulx
ericproulx merged commit 67100ac into ruby-grape:master Jul 23, 2026
35 checks passed
@ericproulx

Copy link
Copy Markdown
Contributor

@schinery I'll make a release this weekend.

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.

Possible regression from 3.2.1 - type: Array + values: [...] produces an extra "is invalid" error in 3.3.0+

2 participants