Skip to content

Report iteration errors on all error nodes #1061

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

Merged
merged 5 commits into from
Jun 5, 2025

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Jun 5, 2025

No description provided.

@Copilot Copilot AI review requested due to automatic review settings June 5, 2025 07:49
key := IterationTypesKey{typeId: t.id, use: use&IterationUseCacheFlags}
// If we are reporting errors and encounter a cached `noIterationTypes`, we should ignore the cached value and continue as if nothing was cached.
// In addition, we should not cache any new results for this call.
noCache := false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

alternatively, I could use nodeId as part of the IterationTypesKey to get the same results

Copy link
Member

Choose a reason for hiding this comment

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

I have a feeling that we might want to do that, just because we can hit this path through regular checker methods externally and then repeatedly tack more diagnostics onto the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

Actually, won't this be like one entry for every single loop, yield, etc, that we check?

Copy link
Member

Choose a reason for hiding this comment

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

Both options seem bad, kinda...

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I guess the way you had it originally was more similar to the original code, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it was more similar - and it only was re-retrieving the iteration types when the cached value had no types. So it seems it should be faster than including the nodeId in the cache key

Copy link
Member

Choose a reason for hiding this comment

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

Okay, then I guess go back, sorry 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed out a revert going back to the noCache variant

@@ -5882,18 +5881,26 @@ func (c *Checker) getIterationTypesOfIterable(t *Type, use IterationUse, errorNo
if IsTypeAny(t) {
return IterationTypes{c.anyType, c.anyType, c.anyType}
}
key := IterationTypesKey{typeId: t.id, use: use&IterationUseCacheFlags | core.IfElse(errorNode != nil, IterationUseReportError, 0)}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

was this even concurrent-checking safe? wouldn't we, potentially, get a different set of errors with multiple error nodes given each concurrent checker could report the error for a different firt encountered errorNode?

Copy link
Member

Choose a reason for hiding this comment

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

So, yes, I agree, though I believe it's handled because we spawn a specific number of checkers and then round robin them, and then they all walk their files in order, so it's always consistent.

But, I think we should probably change it, since this affects the editor and would change if we allow custom checker counts.

fmt
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances error reporting for iteration constructs by ensuring errors are reported on all relevant nodes rather than only the first occurrence.

  • Adjusts the caching logic in getIterationTypesOfIterable to bypass cache when reporting errors.
  • Removes the IterationUseReportError flag and replaces it with a noCache mechanism.
  • Updates baseline snapshots in test data to include the additional expected error lines.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

File Description
internal/checker/checker.go Modified iteration-type caching and error-report logic
testdata/baselines/reference/submodule/conformance/types.forAwait.es2018.2.errors.txt(.diff) Updated expected errors to include additional iteration errors
testdata/baselines/reference/submodule/conformance/for-of16.errors.txt(.diff) Updated expected errors to include additional iteration errors
testdata/baselines/reference/submodule/compiler/omittedExpressionForOfLoop.errors.txt(.diff) Updated expected errors to include additional iteration errors
Comments suppressed due to low confidence (4)

internal/checker/checker.go:5884

  • [nitpick] Consider adding a comment above this cache key definition to explain why the errorNode flag was removed from the key and how the noCache logic affects caching behavior, improving code clarity.
key := IterationTypesKey{typeId: t.id, use: use & IterationUseCacheFlags}

internal/checker/checker.go:5887

  • [nitpick] The variable name noCache is ambiguous; consider renaming it to skipCache or disableCache to more clearly convey its purpose.
noCache := false

internal/checker/checker.go:5901

  • [nitpick] The new noCache parameter in this function signature should be documented in a comment or the method docstring to explain when it is used and its effect on caching.
func (c *Checker) getIterationTypesOfIterableWorker(t *Type, use IterationUse, errorNode *ast.Node, noCache bool) IterationTypes {

internal/checker/checker.go:5882

  • Consider adding unit tests for the scenario where an errorNode is provided and the cached iteration types have no types, to ensure the no-cache path correctly reports all errors on multiple nodes.
func (c *Checker) getIterationTypesOfIterable(t *Type, use IterationUse, errorNode *ast.Node) IterationTypes {

@Andarist Andarist force-pushed the fix/repeat-iteration-errors branch from ab0523f to 24c28f7 Compare June 5, 2025 16:54
@Andarist Andarist force-pushed the fix/repeat-iteration-errors branch from 24c28f7 to a5a4449 Compare June 5, 2025 16:56
@Andarist Andarist requested a review from jakebailey June 5, 2025 17:35
@jakebailey jakebailey closed this Jun 5, 2025
@jakebailey jakebailey reopened this Jun 5, 2025
@jakebailey jakebailey enabled auto-merge June 5, 2025 23:23
@jakebailey jakebailey added this pull request to the merge queue Jun 5, 2025
Merged via the queue into microsoft:main with commit e68fa65 Jun 5, 2025
64 of 125 checks passed
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.

None yet

2 participants