Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Engine/ProtoCore/Lang/BuiltInFunctionEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ public override StackValue Execute(ProtoCore.Runtime.Context c, List<StackValue>
return StackValue.BuildInt(typeUID);
case BuiltInMethods.MethodID.ToStringFromObject:
case BuiltInMethods.MethodID.ToStringFromArray:
case BuiltInMethods.MethodID.ToString:
{
ret = StringUtils.ConvertToString(formalParameters[0], runtimeCore, rmem);
break;
Expand Down
12 changes: 12 additions & 0 deletions src/Engine/ProtoCore/Lang/BuiltInMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
ConditionalIf,
ToStringFromObjectAndFormat,
ToStringFromArrayAndFormat,
ToString,
}

//this array gets accessed using the MethodID enum
Expand Down Expand Up @@ -135,6 +136,7 @@
Constants.kIfConditionalMethodName,
"__ToStringFromObjectAndFormat", // kToStringFromObjectAndFormat
"__ToStringFromArrayAndFormat", // kToStringFromArrayAndFormat
"ToString", // kToString
};

public static string GetMethodName(MethodID id)
Expand Down Expand Up @@ -776,7 +778,7 @@
ReturnType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Bool, 0),
Parameters = new List<KeyValuePair<string, ProtoCore.Type>>
{
new KeyValuePair<string, ProtoCore.Type>("object", TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Var, Constants.kArbitraryRank)),

Check warning on line 781 in src/Engine/ProtoCore/Lang/BuiltInMethods.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of using this literal 'object' 4 times.

See more on https://sonarcloud.io/project/issues?id=DynamoDS_Dynamo&issues=AZ72XZdc2oNuUBvrYZAT&open=AZ72XZdc2oNuUBvrYZAT&pullRequest=17074
},
ID = BuiltInMethods.MethodID.GetType,
MethodAttributes = new MethodAttributes(){Description = Resources.Gettypes}
Expand Down Expand Up @@ -833,6 +835,16 @@
ID = BuiltInMethods.MethodID.ToStringFromArrayAndFormat
},

new BuiltInMethod
{
ReturnType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.String, 0),
Parameters = new List<KeyValuePair<string, ProtoCore.Type>>
{
new KeyValuePair<string, ProtoCore.Type>("object", TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Var, 0)),
},
ID = BuiltInMethods.MethodID.ToString,
},

new BuiltInMethod
{
ReturnType = TypeSystem.BuildPrimitiveTypeObject(PrimitiveType.Void, 0),
Expand Down
52 changes: 52 additions & 0 deletions test/Engine/ProtoTest/TD/MultiLangTests/StringTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,5 +632,57 @@ public void TestStringFromObjectFormat_Prefs2()
ProtoCore.Mirror.MirrorData.PrecisionFormat = oldpref;

}

[Test]
[Category("SmokeTest")]
public void WhenToStringCalledOnIntThenReturnsString()
{
String code =
@"
a = ToString(42);
";
thisTest.RunScriptSource(code);
thisTest.Verify("a", "42");
}

[Test]
[Category("SmokeTest")]
public void WhenToStringCalledOnDoubleThenReturnsString()
{
String code =
@"
a = ToString(1.5);
";
thisTest.RunScriptSource(code);
thisTest.Verify("a", "1.500000");
}

[Test]
[Category("SmokeTest")]
public void WhenToStringCalledOnBoolThenReturnsString()
{
String code =
@"
a = ToString(true);
";
thisTest.RunScriptSource(code);
thisTest.Verify("a", "true");
}

[Test]
[Category("SmokeTest")]
public void WhenToStringUsedInFunctionBodyThenNoWarning()
{
String code =
@"
def formatValues(x : double, y : double)
{
return = ToString(x) + "","" + ToString(y);
}
result = formatValues(1.0, 2.0);
";
thisTest.RunScriptSource(code);
thisTest.Verify("result", "1.000000,2.000000");

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test name says "ThenNoWarning" but the test only asserts the computed string. To make the regression explicit (and avoid the test passing while still emitting a runtime warning), also assert that the runtime warning count is 0 (or rename the test to match what it verifies).

Suggested change
thisTest.Verify("result", "1.000000,2.000000");
thisTest.Verify("result", "1.000000,2.000000");
Assert.AreEqual(0, core.RuntimeStatus.WarningCount);

Copilot uses AI. Check for mistakes.
}
}
}
Loading