Skip to content

Commit d488829

Browse files
committed
fix(parser): Minus operand can be placeholders
1 parent d27f54c commit d488829

4 files changed

Lines changed: 16 additions & 20 deletions

File tree

src/Parser.zig

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,7 @@ fn resolvePlaceholderWithRelation(
19261926
child: *obj.ObjTypeDef,
19271927
resolved_type: *obj.ObjTypeDef,
19281928
final: bool,
1929-
relation: obj.PlaceholderDef.PlaceholderRelation,
1929+
relation: obj.PlaceholderDef.Relation,
19301930
) Error!void {
19311931
const child_placeholder = child.resolved_type.?.Placeholder;
19321932
const child_placeholder_name = self.ast.tokens.items(.lexeme)[child_placeholder.where];
@@ -4205,7 +4205,7 @@ fn literal(self: *Self, _: bool) Error!Ast.Node.Index {
42054205
node.components = .{
42064206
.Double = self.ast.tokens.items(.literal)[node.location].Double,
42074207
};
4208-
node.type_def = self.gc.type_registry.float_type;
4208+
node.type_def = self.gc.type_registry.double_type;
42094209
},
42104210
else => unreachable,
42114211
}
@@ -7082,7 +7082,12 @@ fn binary(self: *Self, _: bool, left: Ast.Node.Index) Error!Ast.Node.Index {
70827082
.EqualEqual,
70837083
=> self.gc.type_registry.bool_type,
70847084

7085-
.Plus => left_type_def orelse right_type_def,
7085+
.Minus,
7086+
.Star,
7087+
.Percent,
7088+
.Slash,
7089+
.Plus,
7090+
=> left_type_def orelse right_type_def,
70867091

70877092
.ShiftLeft,
70887093
.ShiftRight,
@@ -7091,15 +7096,6 @@ fn binary(self: *Self, _: bool, left: Ast.Node.Index) Error!Ast.Node.Index {
70917096
.Xor,
70927097
=> self.gc.type_registry.int_type,
70937098

7094-
.Minus,
7095-
.Star,
7096-
.Percent,
7097-
.Slash,
7098-
=> if ((left_type_def != null and left_type_def.?.def_type == .Double) or (right_type_def != null and right_type_def.?.def_type == .Double))
7099-
self.gc.type_registry.float_type
7100-
else
7101-
self.gc.type_registry.int_type,
7102-
71037099
else => unreachable,
71047100
},
71057101
.components = .{

src/TypeRegistry.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ registry: std.AutoHashMapUnmanaged(TypeDefHash, *o.ObjTypeDef) = .empty,
2323
void_type: *o.ObjTypeDef,
2424
str_type: *o.ObjTypeDef,
2525
int_type: *o.ObjTypeDef,
26-
float_type: *o.ObjTypeDef,
26+
double_type: *o.ObjTypeDef,
2727
bool_type: *o.ObjTypeDef,
2828
any_type: *o.ObjTypeDef,
2929
pat_type: *o.ObjTypeDef,
@@ -37,7 +37,7 @@ pub fn init(gc: *GC) !TypeRegistry {
3737
.void_type = undefined,
3838
.str_type = undefined,
3939
.int_type = undefined,
40-
.float_type = undefined,
40+
.double_type = undefined,
4141
.bool_type = undefined,
4242
.any_type = undefined,
4343
.pat_type = undefined,
@@ -49,7 +49,7 @@ pub fn init(gc: *GC) !TypeRegistry {
4949
self.void_type = try self.getTypeDef(.{ .def_type = .Void });
5050
self.str_type = try self.getTypeDef(.{ .def_type = .String });
5151
self.int_type = try self.getTypeDef(.{ .def_type = .Integer });
52-
self.float_type = try self.getTypeDef(.{ .def_type = .Double });
52+
self.double_type = try self.getTypeDef(.{ .def_type = .Double });
5353
self.bool_type = try self.getTypeDef(.{ .def_type = .Bool });
5454
self.any_type = try self.getTypeDef(
5555
.{

src/obj.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5601,7 +5601,7 @@ pub fn cloneObject(obj: *Obj, vm: *VM) !Value {
56015601
pub const PlaceholderDef = struct {
56025602
const Self = @This();
56035603

5604-
pub const PlaceholderRelation = enum {
5604+
pub const Relation = enum {
56055605
Call,
56065606
Yield,
56075607
Subscript,
@@ -5623,7 +5623,7 @@ pub const PlaceholderDef = struct {
56235623
/// can trace back the root of the unknown type.
56245624
parent: ?*ObjTypeDef = null,
56255625
/// What's the relation with the parent?
5626-
parent_relation: ?PlaceholderRelation = null,
5626+
parent_relation: ?Relation = null,
56275627
/// Children adds themselves here
56285628
children: std.ArrayList(*ObjTypeDef),
56295629
mutable: ?bool,
@@ -5644,7 +5644,7 @@ pub const PlaceholderDef = struct {
56445644
self.children.deinit(allocator);
56455645
}
56465646

5647-
pub fn link(allocator: Allocator, parent: *ObjTypeDef, child: *ObjTypeDef, relation: PlaceholderRelation) !void {
5647+
pub fn link(allocator: Allocator, parent: *ObjTypeDef, child: *ObjTypeDef, relation: Relation) !void {
56485648
assert(parent.def_type == .Placeholder);
56495649
assert(child.def_type == .Placeholder);
56505650

src/value.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub const Value = packed struct {
137137
}
138138

139139
if (self.isDouble()) {
140-
return gc.type_registry.float_type;
140+
return gc.type_registry.double_type;
141141
}
142142

143143
if (self.isInteger()) {
@@ -147,7 +147,7 @@ pub const Value = packed struct {
147147
return switch (self.getTag()) {
148148
TagBoolean => gc.type_registry.bool_type,
149149
TagNull, TagVoid => gc.type_registry.void_type,
150-
else => gc.type_registry.float_type,
150+
else => gc.type_registry.double_type,
151151
};
152152
}
153153

0 commit comments

Comments
 (0)