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

Error quality of life: Forgetting to assign a ?? expression leads to a suprising error? #2037

Open
joshring opened this issue Mar 10, 2025 · 4 comments
Assignees
Labels
Additional info please Further information is requested Enhancement Request New feature or request
Milestone

Comments

@joshring
Copy link
Contributor

Not sure about this one, but I'll see what you think:

module faults;
fault
    EXAMPLE,
    DOG_ATE_MY_HOMEWORK,
    MY_TEXTBOOK_CAUGHT_FIRE,
    DISTRACTED_BY_CAT_PICTURES;


module testing_v0_7;
import faults;
import std::io;

fn int main(String[] args)
{

	int? foo = faults::EXAMPLE?;

	if (catch foo)
	{
		// Error: An optional value may not be discarded, you can ignore it with a void cast '(void)', rethrow on optional with '!' or panic '!!' to avoid this error.
		foo ?? faults::DISTRACTED_BY_CAT_PICTURES?;
		io::printfn("foo = %s", foo)!!;
	}

	return 0;
}
@lerno
Copy link
Collaborator

lerno commented Mar 10, 2025

No this is correct. This is most surely a bug.

@lerno
Copy link
Collaborator

lerno commented Mar 10, 2025

It's also not clear what the user intended:

foo = foo ?? faults::FOO?;
// or
foo ?? faults::FOO?!;

@lerno lerno added the Enhancement Request New feature or request label Mar 10, 2025
@lerno lerno self-assigned this Mar 10, 2025
@lerno lerno added the Additional info please Further information is requested label Mar 10, 2025
@lerno lerno added this to the 0.7.0 milestone Mar 10, 2025
@joshring
Copy link
Contributor Author

It's also not clear what the user intended:

foo = foo ?? faults::FOO?;
// or
foo ?? faults::FOO?!;

I think this is the perfect error message

@lerno
Copy link
Collaborator

lerno commented Mar 13, 2025

This is a general check on discards though, how would you detect and make a reasonable error message?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Additional info please Further information is requested Enhancement Request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants