File tree 4 files changed +31
-2
lines changed
4 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -1463,6 +1463,11 @@ struct String
1463
1463
__intrinsic_op($(kIROp_MakeString ))
1464
1464
__init(double val);
1465
1465
1466
+ [require(cpp)]
1467
+ __implicit_conversion($(kConversionCost_None ))
1468
+ __intrinsic_op($(kIROp_MakeString ))
1469
+ __init(NativeString value);
1470
+
1466
1471
/// Returns the length of the string.
1467
1472
[require(cpp)]
1468
1473
int64_t getLength();
@@ -1502,6 +1507,7 @@ struct NativeString
1502
1507
1503
1508
property int length { [__unsafeForceInlineEarly] get{return getLength();} }
1504
1509
1510
+ __implicit_conversion($(kConversionCost_None ))
1505
1511
__intrinsic_op($(kIROp_getNativeStr ))
1506
1512
__init(String value);
1507
1513
};
Original file line number Diff line number Diff line change @@ -785,8 +785,8 @@ bool SemanticsVisitor::_coerce(
785
785
return true ;
786
786
}
787
787
788
- // If both are string types we assume they are convertable in both directions
789
- if (as<StringTypeBase>(fromType ) && as<StringTypeBase>(toType))
788
+ // Assume string literals are convertible to any string type.
789
+ if (as<StringLiteralExpr>(fromExpr ) && as<StringTypeBase>(toType))
790
790
{
791
791
if (outToExpr)
792
792
*outToExpr = fromExpr;
Original file line number Diff line number Diff line change
1
+ // TEST:EXECUTABLE:
2
+
3
+ void printer(NativeString string )
4
+ {
5
+ printf(string );
6
+ }
7
+
8
+ void indirectPrinter(String string )
9
+ {
10
+ printer(string );
11
+ }
12
+
13
+ export __extern_cpp int main()
14
+ {
15
+ indirectPrinter(" success\n " );
16
+ return 0 ;
17
+ }
Original file line number Diff line number Diff line change
1
+ result code = 0
2
+ standard error = {
3
+ }
4
+ standard output = {
5
+ success
6
+ }
You can’t perform that action at this time.
0 commit comments