Skip to content

Commit 71e9fd0

Browse files
committed
fix(builtins.cast): when sr is casted, it is converted to a string reference prior to cast
1 parent 0f3fb7a commit 71e9fd0

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

compiler/src/builtins/builtins.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,10 @@ struct builtin_cast : builtin {
722722
code << dt_compiler->wrap_in_paren(args[1].first);
723723
} else if (args[1].second.datatype_->is_none()) {
724724
code << "NULL";
725+
} else if (args[1].second.datatype_->const_unwrap()->is_sr()) {
726+
code << "(("
727+
<< dt_compiler->convert_dt(out_dt, datatype_location::CAST, "", "")
728+
<< ")yk__bstr_get_reference(" << args[1].first << "))";
725729
} else {
726730
code << "(("
727731
<< dt_compiler->convert_dt(out_dt, datatype_location::CAST, "", "")

compiler/test_data/bug_fixes/easy_cstr.yaka

+2
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ def myfunc(d: c.CStr) -> None:
55

66
def main() -> int:
77
myfunc(cast("c.CStr", "hello\nworld\n"))
8+
a: sr = "bug\nfix\nis good"
9+
myfunc(cast("c.CStr", a))
810
return 0

compiler/test_data/bug_fixes/easy_cstr.yaka.c

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ void yy__myfunc(yy__c_CStr yy__d)
1414
int32_t yy__main()
1515
{
1616
yy__myfunc(((yy__c_CStr)"hello\nworld\n"));
17+
struct yk__bstr yy__a = yk__bstr_s("bug\nfix\nis good" , 15);
18+
yy__myfunc(((yy__c_CStr)yk__bstr_get_reference(yy__a)));
1719
return INT32_C(0);
1820
}
1921
#if defined(YK__MINIMAL_MAIN)

0 commit comments

Comments
 (0)