diff --git a/src/Generator/AbstractGenerator.php b/src/Generator/AbstractGenerator.php index 3f50dc3..a6c9d16 100644 --- a/src/Generator/AbstractGenerator.php +++ b/src/Generator/AbstractGenerator.php @@ -36,7 +36,7 @@ protected function dumpPHPType(Type $type, callable $importer) : string if ($type instanceof Type\NullableType) { $wrappedType = $type->getWrappedType(); - if ($wrappedType instanceof Type\UnionType) { + if ($wrappedType instanceof Type\UnionType || $wrappedType instanceof ScalarType) { return sprintf('null|%s', $this->dumpPHPType($wrappedType, $importer)); } diff --git a/tests/Generator/AbstractGeneratorTest.php b/tests/Generator/AbstractGeneratorTest.php new file mode 100644 index 0000000..6d7709f --- /dev/null +++ b/tests/Generator/AbstractGeneratorTest.php @@ -0,0 +1,29 @@ +dumpPHPType($type, static fn(string $className) => $className); + } + }; + + self::assertSame( + 'null|int|string|float|bool', + $generator->dump(SymfonyType::nullable(new ScalarType())), + 'Nullable custom scalar output should not use ? with a multi-type union.', + ); + } +}