Skip to content

Commit 3cba69d

Browse files
committed
Create an LlvmIrStringVariable instance when adding a string variable
1 parent 7f96a5e commit 3cba69d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Xamarin.Android.Build.Tasks/Utilities/LlvmIrGenerator/LlvmIrModule.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,19 @@ public LlvmIrGlobalVariable AddGlobalVariable (string name, object value, LlvmIr
267267
/// </summary>
268268
public LlvmIrGlobalVariable AddGlobalVariable (Type type, string name, object? value, LlvmIrVariableOptions? options = null, string? comment = null)
269269
{
270-
var ret = new LlvmIrGlobalVariable (type, name, options) {
271-
Value = value,
272-
Comment = comment,
273-
};
270+
LlvmIrGlobalVariable ret;
271+
if (type == typeof(string)) {
272+
// The cast to `string?` is intentionally meant to throw if `value` type isn't a string.
273+
ret = new LlvmIrStringVariable (name, new StringHolder ((string?)value)) {
274+
Comment = comment,
275+
};
276+
} else {
277+
ret = new LlvmIrGlobalVariable (type, name, options) {
278+
Value = value,
279+
Comment = comment,
280+
};
281+
}
282+
274283
Add (ret);
275284
return ret;
276285
}

0 commit comments

Comments
 (0)