Fixing type bugs
This commit is contained in:
@@ -345,18 +345,6 @@ gen_expr(Ast_Expr *ast){
|
|||||||
if(node->resolved_decl->kind == AST_MODULE_NAMESPACE || node->resolved_decl->kind == AST_FILE_NAMESPACE)
|
if(node->resolved_decl->kind == AST_MODULE_NAMESPACE || node->resolved_decl->kind == AST_FILE_NAMESPACE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/// @edit
|
|
||||||
// if(type_of_var && is_slice(type_of_var) && is_array(node->resolved_decl->type)){
|
|
||||||
// gen("{%d, ", (int)node->resolved_decl->type->arr.size);
|
|
||||||
// gen("%Q}", node->intern_val);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// else if(type_of_var && !is_any(ast->resolved_type) && is_any(type_of_var)){
|
|
||||||
// gen("(Any){&");
|
|
||||||
// gen_expr(ast);
|
|
||||||
// gen(", %d}", ast->resolved_type->type_id);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if(node->resolved_decl->kind == AST_LAMBDA){
|
if(node->resolved_decl->kind == AST_LAMBDA){
|
||||||
gen("%Q", node->resolved_decl->unique_name);
|
gen("%Q", node->resolved_decl->unique_name);
|
||||||
}
|
}
|
||||||
@@ -370,14 +358,6 @@ gen_expr(Ast_Expr *ast){
|
|||||||
}
|
}
|
||||||
|
|
||||||
CASE(VALUE, Atom){
|
CASE(VALUE, Atom){
|
||||||
// @edit
|
|
||||||
// if(is_any(type_of_var)){
|
|
||||||
// gen("(Any){&");
|
|
||||||
// gen("("); gen_simple_decl(node->type); gen("){"); gen_value(node->pos, node->value); gen("}");
|
|
||||||
// gen(", %d}", node->type->type_id);
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
B32 written = gen_value(node->pos, node->value);
|
B32 written = gen_value(node->pos, node->value);
|
||||||
if(!written) {
|
if(!written) {
|
||||||
gen("%Q", node->value.intern_val);
|
gen("%Q", node->value.intern_val);
|
||||||
@@ -393,7 +373,7 @@ gen_expr(Ast_Expr *ast){
|
|||||||
CASE(INDEX, Index){
|
CASE(INDEX, Index){
|
||||||
gen("(");
|
gen("(");
|
||||||
gen_expr(node->expr);
|
gen_expr(node->expr);
|
||||||
if(node->index_original_type == type_string){
|
if(node->index_original_type == type_string || node->index_original_type == untyped_string){
|
||||||
gen(".str");
|
gen(".str");
|
||||||
}
|
}
|
||||||
else if(is_slice(node->index_original_type)){
|
else if(is_slice(node->index_original_type)){
|
||||||
|
|||||||
@@ -1084,7 +1084,7 @@ expr_atom_is_equal_intern(Ast_Expr *expr, Intern_String intern){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Operand
|
function Operand
|
||||||
resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context, Ast_Scope *field_access_scope){
|
resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_and_const_string_context, Ast_Scope *field_access_scope){
|
||||||
if(!ast && is_flag_set(flags, AST_CAN_BE_NULL)) return {};
|
if(!ast && is_flag_set(flags, AST_CAN_BE_NULL)) return {};
|
||||||
assert(is_flag_set(ast->flags, AST_EXPR));
|
assert(is_flag_set(ast->flags, AST_EXPR));
|
||||||
assert(ast->parent_scope->kind == AST_SCOPE || ast->parent_scope->kind == AST_FILE);
|
assert(ast->parent_scope->kind == AST_SCOPE || ast->parent_scope->kind == AST_FILE);
|
||||||
@@ -1165,6 +1165,20 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context, Ast_
|
|||||||
node->resolved_type = type_char;
|
node->resolved_type = type_char;
|
||||||
}
|
}
|
||||||
else if(is_string(left.type)) {
|
else if(is_string(left.type)) {
|
||||||
|
|
||||||
|
// @warning: not sure about this context thing here.
|
||||||
|
// I didn't test it much so might need to delete later.
|
||||||
|
if(is_untyped(left.type)){
|
||||||
|
if(compound_and_const_string_context){
|
||||||
|
if(!is_string(compound_and_const_string_context)){
|
||||||
|
compiler_error(node->pos, "Type mismatch, it's %Q but expected %Q", typestring(left.type), typestring(compound_and_const_string_context));
|
||||||
|
}
|
||||||
|
left.type = compound_and_const_string_context;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
left.type = type_string;
|
||||||
|
}
|
||||||
|
}
|
||||||
node->resolved_type = type_u8;
|
node->resolved_type = type_u8;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1172,6 +1186,7 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context, Ast_
|
|||||||
// we only try to convert the index cause array can't be const
|
// we only try to convert the index cause array can't be const
|
||||||
// right now
|
// right now
|
||||||
try_propagating_resolved_type_to_untyped_literals(node->index, type_s64);
|
try_propagating_resolved_type_to_untyped_literals(node->index, type_s64);
|
||||||
|
try_propagating_resolved_type_to_untyped_literals(node->expr, left.type);
|
||||||
|
|
||||||
if(!left.type)
|
if(!left.type)
|
||||||
compiler_error(node->expr->pos, "Internal compiler error: type of array is null somehow");
|
compiler_error(node->expr->pos, "Internal compiler error: type of array is null somehow");
|
||||||
@@ -1359,7 +1374,7 @@ resolve_expr(Ast_Expr *ast, Resolve_Flag flags, Ast_Type *compound_context, Ast_
|
|||||||
type = op.type_val;
|
type = op.type_val;
|
||||||
}
|
}
|
||||||
if(!type)
|
if(!type)
|
||||||
type = compound_context;
|
type = compound_and_const_string_context;
|
||||||
if(!type)
|
if(!type)
|
||||||
compiler_error(node->pos, "Couldn't infer type of compound expression");
|
compiler_error(node->pos, "Couldn't infer type of compound expression");
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ AnyArguments :: (values: []Any)
|
|||||||
* Written by Lukás Chmela
|
* Written by Lukás Chmela
|
||||||
* Released under GPLv3.
|
* Released under GPLv3.
|
||||||
*/
|
*/
|
||||||
ItoaLookupTable := "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"
|
|
||||||
Itoa :: (value: S64, result: *U8, base: S64): *U8
|
Itoa :: (value: S64, result: *U8, base: S64): *U8
|
||||||
// check that the base if valid
|
// check that the base if valid
|
||||||
if (base < 2) || (base > 36)
|
if (base < 2) || (base > 36)
|
||||||
@@ -31,7 +30,7 @@ Itoa :: (value: S64, result: *U8, base: S64): *U8
|
|||||||
|
|
||||||
|
|
||||||
// @todo: FIX FIX FIX String is untyped
|
// @todo: FIX FIX FIX String is untyped
|
||||||
*ptr++ = ItoaLookupTable[35 + (tmp_value - value * base)]
|
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)]
|
||||||
|
|
||||||
// Apply negative sign
|
// Apply negative sign
|
||||||
if tmp_value < 0
|
if tmp_value < 0
|
||||||
|
|||||||
Reference in New Issue
Block a user