Skip to content

feat: add support for unsigned integer MIN and MAX type bounds#277

Open
metalurgical wants to merge 1 commit intoBlockstreamResearch:masterfrom
metalurgical:issue_252
Open

feat: add support for unsigned integer MIN and MAX type bounds#277
metalurgical wants to merge 1 commit intoBlockstreamResearch:masterfrom
metalurgical:issue_252

Conversation

@metalurgical
Copy link
Copy Markdown
Contributor

@metalurgical metalurgical commented Apr 7, 2026

Introduce parser support for unsigned integer constants (MIN, MAX) across all variants.

Can be further extended easily to include other type specific constants like ZERO, ONE, etc in future.

Extensible for future types that need specific constants as well, without interfering with existing constant types.

@metalurgical metalurgical requested a review from delta1 as a code owner April 7, 2026 12:14
@metalurgical
Copy link
Copy Markdown
Contributor Author

Resolves #252
Closes #252

@KyrylR
Copy link
Copy Markdown
Collaborator

KyrylR commented Apr 9, 2026

Thanks for the contribution!

Overall it LGTM, but there is a nuance with errors

@KyrylR
Copy link
Copy Markdown
Collaborator

KyrylR commented Apr 9, 2026

So now with this example:

fn main() { let pk: Pubkey = witnes::PK; }

Error changed from:

Expected ';', found '::'

to things like:

Expected unsigned integer type before ::
Expected MIN or MAX after unsigned integer type

@KyrylR
Copy link
Copy Markdown
Collaborator

KyrylR commented Apr 9, 2026

image

@metalurgical
Copy link
Copy Markdown
Contributor Author

So now with this example:

fn main() { let pk: Pubkey = witnes::PK; }

Error changed from:

Expected ';', found '::'

to things like:

Expected unsigned integer type before ::
Expected MIN or MAX after unsigned integer type

Thanks for pointing this out. +1

@KyrylR
Copy link
Copy Markdown
Collaborator

KyrylR commented Apr 9, 2026

Nevertheless, would like to hear your opinion on this

Introduce parser support for unsigned integer constants (MIN, MAX) across all variants.

Can be further extended easily to include other type specific constants like ZERO, ONE in future.
@metalurgical
Copy link
Copy Markdown
Contributor Author

Nevertheless, would like to hear your opinion on this

I had incorrectly assumed this case would have been caught by existing tests. Additional tests have been added around this and corrected the implementation here.

Copy link
Copy Markdown
Collaborator

@KyrylR KyrylR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK bbf4cbc; code review

@KyrylR
Copy link
Copy Markdown
Collaborator

KyrylR commented Apr 10, 2026

just for context, waiting for the second review before merging

Copy link
Copy Markdown
Contributor

@stringhandler stringhandler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long time, Strider, I hope you are well. I think it would actually be better to model this properly. It's a Const or a Call at best, rather than a new unique language feature. I would rather say we should treat it as an Ident on the lexer, a Constant(ConstantName) on the parser and AST level, kind of how we do Call. It could maybe even be written as a call.

@metalurgical
Copy link
Copy Markdown
Contributor Author

metalurgical commented Apr 10, 2026

Long time, Strider, I hope you are well.

@stringhandler It has been and likewise.

I think it would actually be better to model this properly. It's a Const or a Call at best, rather than a new unique language feature. I would rather say we should treat it as an Ident on the lexer, a Constant(ConstantName) on the parser and AST level, kind of how we do Call. It could maybe even be written as a call.

The current approach was intentionally limited to address the immediate issue with minimal changes, while leaving room for future extension if needed.

I agree that modelling this as part of a more general language construct would be both sound and a cleaner long-term solution.

The current approach is contained such that it does not prevent transitioning to that model in future.

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.

3 participants