Skip to content

Commit 29981af

Browse files
committed
reduce size of diff by continuing to gen mixed types, for now
1 parent ad9e892 commit 29981af

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

src/Codegen/Constraints/NumberBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function getTypeInfo(): Typing\Type {
128128
return Typing\TypeSystem::num();
129129
} else {
130130
// TODO: Handle hackEnum
131-
return Typing\TypeSystem::mixed();
131+
return Typing\TypeSystem::nonnull();
132132
}
133133
}
134134
}

src/Codegen/Constraints/UntypedBuilder.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,17 @@ private function generateGenericAnyOfChecks(vec<SchemaBuilder> $schema_builders,
497497
}
498498
}
499499

500-
$this->type_info = Typing\TypeSystem::union($present_types);
501-
if ($this->type_info->isOptional()) {
502-
// If the type is optional, don't bother building null builders
503-
// and instead just short-circuit.
500+
$type_info = Typing\TypeSystem::union($present_types);
501+
// For now, keep upcasting nonnull to mixed.
502+
// This is a temporary cludge to reduce the amount of code changed by generating unions.
503+
// TODO: Stop doing the above.
504+
if ($type_info is Typing\ConcreteType && $type_info->getConcreteTypeName() === Typing\ConcreteTypeName::NONNULL) {
505+
$type_info = Typing\TypeSystem::mixed();
506+
}
507+
$this->type_info = $type_info;
508+
if (C\count($nonnull_builders) < C\count($schema_builders)) {
509+
// If we filtered out a null builder above, handle it here.
510+
// TODO: Once we remove the above cludge, we can do `if ($this->type_info->isOptional()) {`
504511
$hb
505512
->startIfBlock('$input === null')
506513
->addReturn(null, HackBuilderValues::export())

tests/BaseCodegenTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private static function getConfig(string $name, this::TOptions $options): Codege
122122
$codegen_config = shape(
123123
'generatedFrom' => '`make test`',
124124
'validator' => $validator_config,
125-
'discardChanges' => true
125+
'discardChanges' => true,
126126
);
127127

128128
$json_schema_codegen_config = $options['json_schema_codegen_config'] ?? null;

tests/examples/codegen/AnyOfValidator2.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
* To re-generate this file run `make test`
66
*
77
*
8-
* @generated SignedSource<<99b51d66245aaffdf4a13563142ea5f5>>
8+
* @generated SignedSource<<72449b6279d0ca5b12355b69be8582b1>>
99
*/
1010
namespace Slack\Hack\JsonSchema\Tests\Generated;
1111
use namespace Slack\Hack\JsonSchema;
1212
use namespace Slack\Hack\JsonSchema\Constraints;
1313

14-
type TAnyOfValidator2 = nonnull;
14+
type TAnyOfValidator2 = mixed;
1515

1616
final class AnyOfValidator2AnyOf0 {
1717

tests/examples/codegen/AnyOfValidatorNestedNullableAnyOf.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* To re-generate this file run `make test`
66
*
77
*
8-
* @generated SignedSource<<c1940fa688271ce27b41f85f8b502a40>>
8+
* @generated SignedSource<<caed5ad653fe7f7d3dfe0516296d4e6b>>
99
*/
1010
namespace Slack\Hack\JsonSchema\Tests\Generated;
1111
use namespace Slack\Hack\JsonSchema;
@@ -84,10 +84,6 @@ public static function check(
8484
mixed $input,
8585
string $pointer,
8686
): TAnyOfValidatorNestedNullableAnyOf {
87-
if ($input === null) {
88-
return null;
89-
}
90-
9187
$constraints = vec[
9288
AnyOfValidatorNestedNullableAnyOfAnyOf0::check<>,
9389
AnyOfValidatorNestedNullableAnyOfAnyOf1::check<>,

tests/examples/codegen/AnyOfValidatorShapes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* To re-generate this file run `make test`
66
*
77
*
8-
* @generated SignedSource<<0a79c5a2b4cdbd407b5c69fb9125b3ed>>
8+
* @generated SignedSource<<fa85e2dfb2ba253b0d8d4d4bf3885c14>>
99
*/
1010
namespace Slack\Hack\JsonSchema\Tests\Generated;
1111
use namespace Slack\Hack\JsonSchema;
@@ -20,7 +20,7 @@
2020
?'foo' => string,
2121
);
2222

23-
type TAnyOfValidatorShapes = nonnull;
23+
type TAnyOfValidatorShapes = mixed;
2424

2525
final class AnyOfValidatorShapesAnyOf0PropertiesFoo {
2626

0 commit comments

Comments
 (0)