Skip to content

Type the identifiers of collected too-wide and missing return type errors as literals - #7296

Open
ondrejmirtes wants to merge 1 commit into
2.3.xfrom
fix-missing-return-identifier-literals
Open

ondrejmirtes wants to merge 1 commit into
2.3.xfrom
fix-missing-return-identifier-literals

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

The Extract identifiers workflow in phpstan/phpstan has been failing for the phpstan-src matrix entry since PHAR 89cdfaa (89cdfaa, the --fix / projectType series). The latest failure is https://github.com/phpstan/phpstan/actions/runs/47061675055:

Internal error: Unknown identifier while analysing file .../src/Rules/Methods/MissingImplementedMethodReturnTypehintRule.php

The extractor's RuleErrorBuilderCollector requires the argument of RuleErrorBuilder::identifier() to be constant strings. These rules pass identifiers they carry in array{string, string, string|null} tuples (message, identifier, tip), or read them back from collected data:

  • MissingImplementedMethodReturnTypehintRule::buildError() / processFixableErrors()
  • MissingFunctionReturnTypehintRule
  • MissingReturnTypeFixRule, through MissingReturnTypeCollector
  • TooWideTypeInOverridableMemberRule, through TooWideTypeInOverridableMemberCollector, OverridableMemberHelper, TooWideTypeCheck, TooWideParameterOutTypeCheck, and TooWideMethodReturnTypehintRule

This follows ac37f68 and changes PHPDoc only. The identifiers are typed as the literals the rules actually produce:

  • For the missing return type rules: 'missingType.return'|'missingType.iterableValue'.
  • For the too-wide rules: a MemberError type alias in TooWideTypeCheck with {return,paramOut,parameterByRef}.{tooWideBool,unusedType} and throws.unusedType (from the throw type rules that also call emitDeclaration()).

Verified locally:

  • phpstan/phpstan's identifier extractor (identifier-extractor/extractor.neon) on this branch completes with valid JSON. Before the change, it stopped with "Unknown identifier" at each of these files in turn.
  • bin/phpstan analyse of the whole project reports no errors.
  • phpcs reports no errors on the changed files.

…rors as literals

The identifier extractor in phpstan/phpstan reads the identifier passed to
RuleErrorBuilder::identifier() as constant strings. The errors that
MissingReturnTypeFixRule and TooWideTypeInOverridableMemberRule report from
collected data, and the ones the missing return type rules build from their
lists of errors, carried the identifier typed as string, so the extraction
of phpstan-src failed with "Unknown identifier".

Amp-Thread-ID: https://ampcode.com/threads/T-01a19770-5331-74b2-963f-e324ae0f7635
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.

1 participant