Skip to content
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

Fix invalid array bounds during static analysis #518

Merged
merged 1 commit into from
May 21, 2024

Conversation

veewee
Copy link
Contributor

@veewee veewee commented May 17, 2024

Fixes php-soap/wsdl-reader#26

@lstrojny : I decided to go this way since it is the easiest way to go forward.

The array-bounds will always be calculated based on int<0, maxOccurs - 1>:
When minOccurs > 0, the array will become a non-empty-array.

Examples:

// minOccurs=0, maxOccurs=-1
array<int<0, max>, Tv>

// minOccurs=1, maxOccurs=-1
non-empty-array<int<0, max>, Tv>

// minOccurs=0, maxOccurs=0
array<never, Tv>

// minOccurs=0, maxOccurs=1
array<int<0,0>, Tv>

// minOccurs=0, maxOccurs=2
array<int<0,1>, Tv>

// minOccurs=1, maxOccurs=2
non-empty-array<int<0,1>, Tv>

This should solve your issue.

If someone cares enough to improve this, I'm always open into considering something like:

array{0: string, 1 ?: string, ...string}

(limited to x amount of items to avoid too large shapes being generated)

Yet I think this should be sufficient for now.

@veewee veewee force-pushed the improved-bounds-calculations branch from 7fc8dee to c2b02c4 Compare May 17, 2024 13:01
@lstrojny
Copy link
Contributor

Tried and the solutions works perfectly fine. Thank you!

@veewee veewee merged commit 66eb962 into phpro:v3.x May 21, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect array bounds in docs
2 participants