Skip to content

Commit

Permalink
Throw parser error in case direct recursive types are not nullable (#…
Browse files Browse the repository at this point in the history
…41866)

Summary:
Pull Request resolved: #41866

Direct recursive member types require infinite memory and aren't possible with current hardware.

Throw parser error to make this visible.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D51999832

fbshipit-source-id: 671f87325f33dd24f70ff3e2229c9d0b888d7445
  • Loading branch information
christophpurrer authored and facebook-github-bot committed Dec 12, 2023
1 parent 8bcaed9 commit 4187a8c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/react-native-codegen/src/parsers/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,20 @@ class UnsupportedObjectPropertyValueTypeAnnotationParserError extends ParserErro
}
}

class UnsupportedObjectDirectRecursivePropertyParserError extends ParserError {
constructor(
propertyName: string,
propertyValueAST: $FlowFixMe,
nativeModuleName: string,
) {
super(
nativeModuleName,
propertyValueAST,
`Object property '${propertyName}' is direct recursive and must be nullable.`,
);
}
}

/**
* Function parsing errors
*/
Expand Down Expand Up @@ -405,6 +419,7 @@ module.exports = {
UnsupportedModulePropertyParserError,
UnsupportedObjectPropertyTypeAnnotationParserError,
UnsupportedObjectPropertyValueTypeAnnotationParserError,
UnsupportedObjectDirectRecursivePropertyParserError,
UnusedModuleInterfaceParserError,
MoreThanOneModuleRegistryCallsParserError,
UntypedModuleRegistryCallParserError,
Expand Down
8 changes: 8 additions & 0 deletions packages/react-native-codegen/src/parsers/parsers-commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const {
MissingTypeParameterGenericParserError,
MoreThanOneTypeParameterGenericParserError,
UnnamedFunctionParamParserError,
UnsupportedObjectDirectRecursivePropertyParserError,
} = require('./errors');
const {
createParserErrorCapturer,
Expand Down Expand Up @@ -208,6 +209,13 @@ function parseObjectProperty(
: parentObject.id &&
parentObject.id.name === languageTypeAnnotation.id?.name)
) {
if (!optional) {
throw new UnsupportedObjectDirectRecursivePropertyParserError(
name,
languageTypeAnnotation,
hasteModuleName,
);
}
return {
name,
optional,
Expand Down

0 comments on commit 4187a8c

Please sign in to comment.