improve int/float type resolution
This commit is contained in:
@@ -4205,7 +4205,11 @@ record_field_expr_candidate :: proc(
|
|||||||
}
|
}
|
||||||
expr := checker.ast_module.exprs[expr_id]
|
expr := checker.ast_module.exprs[expr_id]
|
||||||
constraint := checker.record_field_constraints[slot]
|
constraint := checker.record_field_constraints[slot]
|
||||||
if !numeric_operand_is_open(checker, expr_id, locals, pkg, file) {
|
open := numeric_operand_is_open(checker, expr_id, locals, pkg, file)
|
||||||
|
if open && is_runtime_type(checker, checker.module.types.fields[slot].type) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !open {
|
||||||
concrete := types.constraint_target(constraint, inferred, &checker.module.types)
|
concrete := types.constraint_target(constraint, inferred, &checker.module.types)
|
||||||
if is_runtime_type(checker, concrete) {
|
if is_runtime_type(checker, concrete) {
|
||||||
return merge_record_field_demand(checker, slot, concrete, expr.span)
|
return merge_record_field_demand(checker, slot, concrete, expr.span)
|
||||||
@@ -4224,7 +4228,7 @@ record_field_expr_candidate :: proc(
|
|||||||
if is_float_constant_expr(checker, expr_id) {
|
if is_float_constant_expr(checker, expr_id) {
|
||||||
return merge_record_field_default(checker, slot, types.F64, expr.span)
|
return merge_record_field_default(checker, slot, types.F64, expr.span)
|
||||||
}
|
}
|
||||||
if numeric_operand_is_open(checker, expr_id, locals, pkg, file) {
|
if open {
|
||||||
candidate := inferred
|
candidate := inferred
|
||||||
if constraint == types.FLOAT && types.is_concrete_integer(candidate) {
|
if constraint == types.FLOAT && types.is_concrete_integer(candidate) {
|
||||||
candidate = types.F64
|
candidate = types.F64
|
||||||
|
|||||||
+13
-1
@@ -14865,7 +14865,19 @@ exercise func(cursor usize, narrow i8, wider i16, count i32) i32 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
main func() i32 { return exercise(7, 1, 1000, 3) }
|
scan_open_cursor func() void {
|
||||||
|
cursor := 0
|
||||||
|
first Token := Token{start = cursor}
|
||||||
|
second Token := Token{start = cursor}
|
||||||
|
_ = first
|
||||||
|
_ = second
|
||||||
|
}
|
||||||
|
|
||||||
|
main func() i32 {
|
||||||
|
result := exercise(7, 1, 1000, 3)
|
||||||
|
scan_open_cursor()
|
||||||
|
return result
|
||||||
|
}
|
||||||
`
|
`
|
||||||
source_file := source.Source{path="record_constraints.bro", text=text}
|
source_file := source.Source{path="record_constraints.bro", text=text}
|
||||||
diagnostics := source.init_diagnostics(&source_file)
|
diagnostics := source.init_diagnostics(&source_file)
|
||||||
|
|||||||
Reference in New Issue
Block a user