Skip to content

Fix GH-269: Render union and intersection types in IDE formats - #271

Open
RaphaelFakhri wants to merge 1 commit into
php:masterfrom
RaphaelFakhri:fix-ide-union-types
Open

RaphaelFakhri wants to merge 1 commit into
php:masterfrom
RaphaelFakhri:fix-ide-union-types

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

The IDE package formats (json, xml, php, sqlite, phpstub) keep only the text of the last <type> element they read. For a union or intersection type, every nested <type> overwrites the previous one, so array_key_first() gets null as its return type instead of int|string|null. Parameter types are affected the same way.

Changes

  • Package_IDE_Base now handles the <type> element and builds the type from its nested <type> children: union members are joined with |, intersection members with &, and an intersection nested in a union is wrapped in parentheses (DNF types, for example (Countable&Traversable)|null).
  • Package_IDE_XML escapes the parameter and return types, so an intersection type does not produce invalid XML.
  • New test tests/package/ide/type_rendering_001.phpt covers union, intersection and DNF types for the JSON and XML formats.

Example output for array_key_first() in the json format:

-"return":{"type":"null",...}
+"return":{"type":"int|string|null",...}

Tests

make test: 65 tests pass. The new test fails without the change to Package_IDE_Base.

This change does not cover the missing initializers that are wrapped in <constant>, also reported in GH-269.

The IDE formats kept only the last member of a union or intersection
type, so array_key_first() was documented as returning null instead of
int|string|null. Build the full type from the nested <type> elements,
including DNF types, and escape types in the IDE XML output.
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