Repository navigation
Declare ArgValues arrays in type position - #360
Merged
sidepelican merged 1 commit intoSep 8, 2026
Merged
Conversation
With `--enable-args-history` the generated capture array was declared as `var xArgValues = [(a: A, b: B)]()`. In that form Swift has to guess whether `[...]` is a type or an array literal, and it decides by resolving each name the way it would in an expression. A property or method named `Config` then hides the `Config` type, and a `()` element is already a value, so Swift settles on the array literal and the mock fails to compile: error: cannot call value of non-function type '[(config: Int?, force: Bool.Type)]' error: cannot use instance member 'Config' within property initializer error: cannot use optional chaining on non-optional value of type 'Int' error: cannot call value of non-function type '[(event: (), verbose: Bool.Type)]' With `var xArgValues: [(a: A, b: B)] = []` the annotation is unambiguously a type, so the guess never happens. Tuple shape alone does not trigger the failure: optional, dictionary, existential, generic and nested element types compile in either form. The concurrency-safe branch of the same template already used `xArgValues: [T]`, so both paths now render the same way. - Template: emit `var xArgValues: [T] = []` instead of `var xArgValues = [T]()`. - 23 existing fixture lines rewritten to the annotated form; no other output changes. - New compiled fixture `argumentsHistoryMemberShadowsTypeName` proving the annotated form compiles next to a `var Config: Int` member that shadows the `Config` type, and next to a `()`-typed parameter. - README arguments-history example updated to the emitted form. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
sidepelican
approved these changes
Sep 8, 2026
sidepelican
left a comment
Collaborator
There was a problem hiding this comment.
Looks good. Nice catch! Thank you.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
With
--enable-args-history, the generated capture array is declared asvar xArgValues = [(a: A, b: B)](). In that form Swift has to guess whether[...]is a type or an array literal, and it decides by resolving each name the way it would in an expression. A property or method namedConfigthen hides theConfigtype, and a()element is already a value, so Swift settles on the array literal and the mock fails to compile. Withvar xArgValues: [(a: A, b: B)] = []the annotation is unambiguously a type, so the guess never happens.Example
Before: the stored
Configproperty hides the type. Swift readsConfig?as optional chaining on anIntandBoolas a value representing the type.()is already an expression and fails on its own:After: the same mock uses explicit type annotations:
Tuple shape alone does not trigger the failure: optional, dictionary, existential, generic and nested element types compile in either form. The concurrency-safe branch of the same template already used
xArgValues: [T], so both paths now render the same way.Test plan
Added compiled
@FixtureargumentsHistoryMemberShadowsTypeNameusing the protocol above. The expected mock compiles as part of the test target with the shadowingvar Config: Intmember and the()-typed parameter. Compilation verifies the fix: the previous= [...]()form fails there. Updated 23 existing fixture lines to use annotations, with no other output changes.swift build && swift testpasses.🤖 Generated with Claude Code