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

Editorial: Fix omitted return types of functions that can return empty #3434

Closed
wants to merge 1 commit into from

Conversation

kimjg1119
Copy link
Contributor

@kimjg1119 kimjg1119 commented Oct 2, 2024

Certain functions may return ~empty~, though this is not always reflected in the return type. Each identified error is presented alongside specific code examples, where scenarios include the presence of ~empty~ values.

All of these errors were discovered using ESMeta, so executing the provided code in ESMeta may help obtain a detailed execution path(Also note that some of the codes only compile in the dev branch).

Fixed functions

LabelledEvaluation

LabelledEvaluation of LabelledItem with argument newLabelSet can return ~empty~ because of the break statement, the return value can be ~empty~.

Scenario:

label: break label;
label: function f() {}
label: {}
label: var x;
label: ;
Details (ESMeta)

[ReturnTypeMismatch] Block[12989] return statement in LabelledStatement[0,0].LabelledEvaluation (step 5, 7:12-34)
- expected: Normal[ESValue] | Abrupt
- actual  : Normal[ESValue | Enum[~empty~]] | Abrupt[break, continue, throw]

[ReturnTypeMismatch] Block[12991] return statement in LabelledItem[1,0].LabelledEvaluation (step 1, 2:12-57)
- expected: Normal[ESValue] | Abrupt
- actual  : Normal[Enum[~empty~]]

[ReturnTypeMismatch] Block[12993] return statement in Statement[0,0].LabelledEvaluation (step 1, 2:12-47)
- expected: Normal[ESValue] | Abrupt
- actual  : Normal[ESValue | Enum[~empty~]] | Abrupt[break, continue, throw]

[ReturnTypeMismatch] Block[12995] return statement in Statement[1,0].LabelledEvaluation (step 1, 2:12-47)
- expected: Normal[ESValue] | Abrupt
- actual  : Normal[Enum[~empty~]] | Throw

[ReturnTypeMismatch] Block[12997] return statement in Statement[2,0].LabelledEvaluation (step 1, 2:12-47)
- expected: Normal[ESValue] | Abrupt
- actual  : Normal[Enum[~empty~]]

CatchClauseEvaluation

The Completion(Evaluation of Block) could result in ~empty~. Since it flows into B and returns immediately, the return type should account for ~empty~.

Scenario:

try { x; } catch (e) {}
try { x; } catch {}

Note that each line corresponds to the bug in the details.

Details (ESMeta)

[ReturnTypeMismatch] Block[13050] return statement in Catch[0,0].CatchClauseEvaluation (step 9, 13:12-25)
- expected: Normal[ESValue] | Abrupt
- actual  : Normal[ESValue | Enum[~empty~]] | Abrupt[break, continue, throw]

[ReturnTypeMismatch] Block[13052] return statement in Catch[1,0].CatchClauseEvaluation (step 1, 2:12-43)
- expected: Normal[ESValue] | Abrupt
- actual  : Normal[ESValue | Enum[~empty~]] | Abrupt[break, continue, throw]

EvaluateFunctionBody

Since the evaluation of a single block is an ~empty~, an evaluation of the FunctionStatementList can be ~empty~ too.

Scenario:

function f() { {} } f();
Details (ESMeta)

[ReturnTypeMismatch] Block[13224] return statement in FunctionBody[0,0].EvaluateFunctionBody (step 2, 3:12-59)
- expected: Normal[ESValue] | Abrupt
- actual  : Normal[ESValue | Enum[~empty~]] | Abrupt[break, continue, throw]

EvaluateClassStaticBlockBody

Similar to EvaluateFunctionBody, this function can return ~empty~.

Scenario:

class A { static { {} } }
Details (ESMeta)

[ReturnTypeMismatch] Block[14021] return statement in ClassStaticBlockBody[0,0].EvaluateClassStaticBlockBody (step 3, 4:12-67)
- expected: Normal[ESValue] | Abrupt
- actual  : Normal[ESValue | Enum[~empty~]] | Abrupt[break, continue, throw]

@nicolo-ribaudo
Copy link
Member

Note about the title: this is Editorial, because the change is not observable from JS code.

@kimjg1119 kimjg1119 changed the title Normative: Fix omitted return types of functions that can return empty Editorial: Fix omitted return types of functions that can return empty Oct 2, 2024
@kimjg1119 kimjg1119 marked this pull request as ready for review October 2, 2024 11:06
@bakkot
Copy link
Contributor

bakkot commented Oct 2, 2024

This is a duplicate of #2924. Apologies for leaving that open for so long; I'm hoping we can merge it soon.

@bakkot bakkot closed this Oct 2, 2024
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