Skip to content

Commit

Permalink
fix(builtins.cast): when sr is casted, it is converted to a string re…
Browse files Browse the repository at this point in the history
…ference prior to cast
  • Loading branch information
JaDogg committed Apr 27, 2024
1 parent 0f3fb7a commit 71e9fd0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/src/builtins/builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,10 @@ struct builtin_cast : builtin {
code << dt_compiler->wrap_in_paren(args[1].first);
} else if (args[1].second.datatype_->is_none()) {
code << "NULL";
} else if (args[1].second.datatype_->const_unwrap()->is_sr()) {
code << "(("
<< dt_compiler->convert_dt(out_dt, datatype_location::CAST, "", "")
<< ")yk__bstr_get_reference(" << args[1].first << "))";
} else {
code << "(("
<< dt_compiler->convert_dt(out_dt, datatype_location::CAST, "", "")
Expand Down
2 changes: 2 additions & 0 deletions compiler/test_data/bug_fixes/easy_cstr.yaka
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ def myfunc(d: c.CStr) -> None:

def main() -> int:
myfunc(cast("c.CStr", "hello\nworld\n"))
a: sr = "bug\nfix\nis good"
myfunc(cast("c.CStr", a))
return 0
2 changes: 2 additions & 0 deletions compiler/test_data/bug_fixes/easy_cstr.yaka.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ void yy__myfunc(yy__c_CStr yy__d)
int32_t yy__main()
{
yy__myfunc(((yy__c_CStr)"hello\nworld\n"));
struct yk__bstr yy__a = yk__bstr_s("bug\nfix\nis good" , 15);
yy__myfunc(((yy__c_CStr)yk__bstr_get_reference(yy__a)));
return INT32_C(0);
}
#if defined(YK__MINIMAL_MAIN)
Expand Down

0 comments on commit 71e9fd0

Please sign in to comment.