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 of * .. non-number Range scenarios #5377

Closed
wants to merge 2 commits into from

Conversation

2colours
Copy link
Contributor

Resolves #5340
The whatever-star is always inferred to mean +/- Inf in Range
constructions, therefore it makes sense to infer the same rules for it as for Inf itself. Since modifying the type constraint changed the order of the resolution of 10 .. ^20 (might be a bug in itself), I rather made a coercion to Real in the function body.

constructions, therefore it makes sense to infer the same rules for
it as for Inf itself. Since modifying the type constraint changed
the order of the resolution of 10 .. ^20 (might be a bug in itself),
I rather made a coercion to Real in the function body.
src/core.c/Range.rakumod Outdated Show resolved Hide resolved
@@ -57,10 +57,12 @@ my class Range is Cool does Iterable does Positional {
nqp::create(self)!SET-SELF(-Inf,Inf,$excludes-min,$excludes-max,1);
}
multi method new(Whatever \min, \max, :$excludes-min, :$excludes-max) {
nqp::create(self)!SET-SELF(-Inf,max,$excludes-min,$excludes-max,1);
use fatal;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm.. but then why the "use fatal". I seem to be missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because otherwise max.Real as a Failure will simply be passed on, and a monstrous Range (that starts/ends with a Failure) will be created.

Copy link
Contributor

Choose a reason for hiding this comment

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

Aha, ok, then maybe SET-SELF would need an $max.throw if nqp::istype($max,Failure) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably it should check for both $min and $max; I'm not sure of the performance implications. Right now, the other cases only throw because they tried to retrieve the failed value before doing the function call.

@2colours
Copy link
Contributor Author

@lizmat well, it would be good to get this over with. I didn't want to add the check to !SET-SELF because that's common path and I felt that could be heavier on the performance. If I have this wrong, or it's insignificant here, sure I can just change to that. Either is better than leaving it as it is.

@lizmat
Copy link
Contributor

lizmat commented Nov 9, 2023

Question: did you actually spectest these changes? I see pretty massive test failures with make spectest.

Turns out spectests say that "a"..* and *..'b' are considered valid ranges.

Therefore closing this PR.

@lizmat lizmat closed this Nov 9, 2023
@2colours 2colours deleted the whatever-range-fix branch November 23, 2023 09:31
@2colours
Copy link
Contributor Author

Turns out spectests say that "a"..* and *..'b' are considered valid ranges.

That's quite bad given that they literally create ranges that are forbidden otherwise. I'm gonna open an issue for it.

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.

WhateverStar dodges range sanity check
2 participants