diff --git a/Core/tests/ExpressionParser2.cpp b/Core/tests/ExpressionParser2.cpp index f4b1d247e752..e2604f295bea 100644 --- a/Core/tests/ExpressionParser2.cpp +++ b/Core/tests/ExpressionParser2.cpp @@ -49,6 +49,8 @@ TEST_CASE("ExpressionParser2", "[common][events]") { mySpriteObject.GetVariables().InsertNew("MyVariable3"); mySpriteObject.GetVariables().InsertNew("MyNumberVariable").SetValue(123); mySpriteObject.GetVariables().InsertNew("MyStringVariable").SetString("Test"); + // A variable with the same name as the object. + mySpriteObject.GetVariables().InsertNew("MySpriteObject"); auto &mySpriteObject2 = layout1.InsertNewObject(project, "MyExtension::Sprite", "MySpriteObject2", 1); mySpriteObject2.GetVariables().InsertNew("MyVariable", 0); mySpriteObject2.GetVariables().InsertNew("MyVariable2", 1); @@ -1685,6 +1687,27 @@ TEST_CASE("ExpressionParser2", "[common][events]") { } } + SECTION("Variable with the same name as an object") { + auto node = parser.ParseExpression("MySpriteObject.MySpriteObject"); + REQUIRE(node != nullptr); + + gd::ExpressionValidator validator(platform, projectScopedContainers, + "number|string"); + node->Visit(validator); + REQUIRE(validator.GetFatalErrors().size() == 0); + REQUIRE(validator.GetAllErrors().size() == 0); + } + + SECTION("Variable with the same name as an object (with child-variables)") { + auto node = parser.ParseExpression("MySpriteObject.MySpriteObject.MyChild.MyChild"); + REQUIRE(node != nullptr); + + gd::ExpressionValidator validator(platform, projectScopedContainers, "number|string"); + node->Visit(validator); + REQUIRE(validator.GetFatalErrors().size() == 0); + REQUIRE(validator.GetAllErrors().size() == 0); + } + SECTION("Invalid object variables (1 level, non existing object)") { { auto node = diff --git a/newIDE/app/src/EventsSheet/ParameterFields/AnyVariableField.js b/newIDE/app/src/EventsSheet/ParameterFields/AnyVariableField.js index 2a0a2939e475..b8e0f2eba529 100644 --- a/newIDE/app/src/EventsSheet/ParameterFields/AnyVariableField.js +++ b/newIDE/app/src/EventsSheet/ParameterFields/AnyVariableField.js @@ -92,6 +92,7 @@ export default React.forwardRef( forceDeclaration project={project} instruction={instruction} + isObjectVariable={false} variablesContainers={variablesContainers} enumerateVariables={enumerateGlobalAndSceneVariables} parameterMetadata={props.parameterMetadata} diff --git a/newIDE/app/src/EventsSheet/ParameterFields/GlobalVariableField.js b/newIDE/app/src/EventsSheet/ParameterFields/GlobalVariableField.js index 210bbfaef1b2..e3c7c9064bcc 100644 --- a/newIDE/app/src/EventsSheet/ParameterFields/GlobalVariableField.js +++ b/newIDE/app/src/EventsSheet/ParameterFields/GlobalVariableField.js @@ -48,6 +48,7 @@ export default React.forwardRef( return ( ( } project={project} instruction={instruction} + isObjectVariable={true} variablesContainers={variablesContainers} enumerateVariables={enumerateObjectVariables} parameterMetadata={props.parameterMetadata} diff --git a/newIDE/app/src/EventsSheet/ParameterFields/SceneVariableField.js b/newIDE/app/src/EventsSheet/ParameterFields/SceneVariableField.js index 1767151825f7..b9daad4fc2f9 100644 --- a/newIDE/app/src/EventsSheet/ParameterFields/SceneVariableField.js +++ b/newIDE/app/src/EventsSheet/ParameterFields/SceneVariableField.js @@ -49,6 +49,7 @@ export default React.forwardRef( return ( , enumerateVariables: () => Array, forceDeclaration?: boolean, @@ -94,7 +95,8 @@ export const getRootVariableName = (name: string): string => { export const quicklyAnalyzeVariableName = ( name: string, variablesContainers?: Array, - projectScopedContainersAccessor?: ProjectScopedContainersAccessor + projectScopedContainersAccessor?: ProjectScopedContainersAccessor, + isObjectVariable: boolean = false ): VariableNameQuickAnalyzeResult => { if (!name) return VariableNameQuickAnalyzeResults.OK; @@ -121,6 +123,7 @@ export const quicklyAnalyzeVariableName = ( const rootVariableName = getRootVariableName(name); if ( + !isObjectVariable && projectScopedContainersAccessor && projectScopedContainersAccessor .get() @@ -196,6 +199,7 @@ export default React.forwardRef( onApply, id, onInstructionTypeChanged, + isObjectVariable, } = props; const field = React.useRef(null); @@ -286,7 +290,8 @@ export default React.forwardRef( const quicklyAnalysisResult = quicklyAnalyzeVariableName( value, variablesContainers, - projectScopedContainersAccessor + projectScopedContainersAccessor, + isObjectVariable ); const errorText =