Skip to content

#3057. Add more try-catch-finally tests #3146

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

Closed
wants to merge 1 commit into from

Conversation

sgrekhov
Copy link
Contributor

No description provided.

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

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

Looks good! I think, however, that a few cases are expected to pass, but must be errors.

if (s is T) {}
} catch (_) {
(s,) = (T(),);
s.answer();
Copy link
Member

Choose a reason for hiding this comment

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

I would expect this one to fail because before(S0) = conservativeJoin(before(N), ...), where T is not a type of interest for s.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But according to the dart-lang/sdk#60519 this should be an error.

Copy link
Member

Choose a reason for hiding this comment

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

Exactly, it should be an error because T is not a type of interest for s at the location of the pattern assignment.

Copy link
Member

Choose a reason for hiding this comment

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

However, I just created dart-lang/language#4328 in order to clarify the situation: The implemented behavior appears to be different from the specified behavior.

if (s is T) {}
} catch (_) {
(s,) = (T(),);
s.answer();
Copy link
Member

Choose a reason for hiding this comment

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

I'd expect this to fail because each alternative starts with before(N) (plus some assigned and some captured bits, but they won't change anything about types of interest).

s.answer();
} finally {
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Right, we should certainly test try/catch/finally even though it's not yet in the spec. Best effort, as usual. ;-)

But I guess they'd fit better in a series of tests named reachability_try_catch_finally_A*_t*.dart.

if (s is T) {}
} catch (_) {
(s,) = (T(),);
s.answer();
Copy link
Member

Choose a reason for hiding this comment

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

This one should again fail, considering that the catch blocks have no more than before(N) when it comes to types of interest.

} catch (_) {
} finally {
(x: s) = (x: T());
s.answer();
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

/// - Let `after(N) = restrict(after(B1), after(B2), assignedIn(B2))`
///
/// @description Checks that if a type `T` is made a type of interest in a catch
/// part of `B1` then it can be promoted in `B1`, `B2` and `after(N)`.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think B1 can include a catch part. I think we have rules about try .. catch .. catch and about try .. finally, but the rule about try .. catch .. catch .. finally is missing.

So we're testing try-catch-finally statements as a separate kind of case, noting that these tests must be revisited when the spec rule is in place.

if (s is T) {}
} catch (_) {
(s,) = (T(),);
s.answer();
Copy link
Member

Choose a reason for hiding this comment

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

This should fail, S0 is not a predecessor of S1 in the flow graph.

if (s is T) {}
} finally {
(x: s) = (x: T());
s.answer();
Copy link
Member

Choose a reason for hiding this comment

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

Similarly, the catch block is not a predecessor of the finally block.

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

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

(Clarifications)

if (s is T) {}
} catch (_) {
(s,) = (T(),);
s.answer();
Copy link
Member

Choose a reason for hiding this comment

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

Exactly, it should be an error because T is not a type of interest for s at the location of the pattern assignment.

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

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

I think this one might need to be blocked on a spec clarification, too: dart-lang/language#4328.

if (s is T) {}
} catch (_) {
(s,) = (T(),);
s.answer();
Copy link
Member

Choose a reason for hiding this comment

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

However, I just created dart-lang/language#4328 in order to clarify the situation: The implemented behavior appears to be different from the specified behavior.

@sgrekhov sgrekhov marked this pull request as draft April 16, 2025 08:18
@sgrekhov
Copy link
Contributor Author

Partially tests are duplicates of existing ones, partially replaced by #3148. Closing this one.

@sgrekhov sgrekhov closed this Apr 16, 2025
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.

2 participants