Skip to content

Commit a9cd2b3

Browse files
committed
Fixed bug with default types for number literals
1 parent bd04149 commit a9cd2b3

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/semantic/unify.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ Result<Ok, Error> semantic::unify_types_and_type_check(Context& context, ast::In
170170
if (node.type.is_final_type_variable() && (
171171
!context.current_function.has_value()
172172
|| !context.current_function.value()->is_in_type_parameter(node.type))) {
173-
semantic::set_unified_type(context, node.type, ast::Type("Int64"));
174-
node.type = ast::Type("Int64");
173+
auto default_type = ast::get_default_type(context.type_inference.interface_constraints[node.type]);
174+
semantic::set_unified_type(context, node.type, default_type);
175+
node.type = default_type;
175176
}
176177

177178

@@ -184,8 +185,9 @@ Result<Ok, Error> semantic::unify_types_and_type_check(Context& context, ast::Fl
184185
if (node.type.is_final_type_variable() && (
185186
!context.current_function.has_value()
186187
|| !context.current_function.value()->is_in_type_parameter(node.type))) {
187-
semantic::set_unified_type(context, node.type, ast::Type("Float64"));
188-
node.type = ast::Type("Float64");
188+
auto default_type = ast::get_default_type(context.type_inference.interface_constraints[node.type]);
189+
semantic::set_unified_type(context, node.type, default_type);
190+
node.type = default_type;
189191
}
190192

191193
return Ok {};

test/type_inference/type_inference_1.dmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
a = 10.0
1+
a = 10
22
print(20.5 + a) -- a = 10 won't work until having interfaces
33

44
--- Output

test/type_inference/type_inference_2.dmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
a = 10 : Int32
22
print(a + 3)
33

4-
a = 50 : Int8
4+
a = 50
55
b = 3 : Int8
66
print(a + b) -- a = 50 won't work until having interfaces
77

0 commit comments

Comments
 (0)