mirror of
https://github.com/roc-lang/roc.git
synced 2025-11-03 14:12:53 +00:00
Merge pull request #7793 from roc-lang/bhansconnect/push-ltlytlqrmnmx
Deal with bad offset for identifier
This commit is contained in:
commit
e8ee97694d
5 changed files with 37 additions and 20 deletions
|
|
@ -1411,13 +1411,13 @@ pub const NodeStore = struct {
|
|||
.ty => |t| {
|
||||
node.tag = .ty_ty;
|
||||
node.region = t.region;
|
||||
node.main_token = t.tok;
|
||||
node.main_token = t.region.start;
|
||||
node.data.rhs = @bitCast(t.ident);
|
||||
},
|
||||
.mod_ty => |t| {
|
||||
node.tag = .ty_mod_ty;
|
||||
node.region = t.region;
|
||||
node.main_token = t.tok;
|
||||
node.main_token = t.region.start;
|
||||
node.data.lhs = @bitCast(t.mod_ident);
|
||||
node.data.rhs = @bitCast(t.ty_ident);
|
||||
},
|
||||
|
|
@ -2097,14 +2097,12 @@ pub const NodeStore = struct {
|
|||
},
|
||||
.ty_ty => {
|
||||
return .{ .ty = .{
|
||||
.tok = node.main_token,
|
||||
.ident = @bitCast(node.data.rhs),
|
||||
.region = node.region,
|
||||
} };
|
||||
},
|
||||
.ty_mod_ty => {
|
||||
return .{ .mod_ty = .{
|
||||
.tok = node.main_token,
|
||||
.mod_ident = @bitCast(node.data.lhs),
|
||||
.ty_ident = @bitCast(node.data.rhs),
|
||||
.region = node.region,
|
||||
|
|
@ -2615,14 +2613,14 @@ pub const NodeStore = struct {
|
|||
region: Region,
|
||||
},
|
||||
ty: struct {
|
||||
tok: TokenIdx,
|
||||
ident: base.Ident.Idx,
|
||||
// Region starts with the type token.
|
||||
region: Region,
|
||||
},
|
||||
mod_ty: struct {
|
||||
tok: TokenIdx,
|
||||
mod_ident: base.Ident.Idx,
|
||||
ty_ident: base.Ident.Idx,
|
||||
// Region starts with the mod token and ends with the type token.
|
||||
region: Region,
|
||||
},
|
||||
tag_union: struct {
|
||||
|
|
@ -2687,14 +2685,14 @@ pub const NodeStore = struct {
|
|||
// (ty name)
|
||||
.ty => |a| {
|
||||
var node = sexpr.Expr.init(env.gpa, "ty");
|
||||
node.appendStringChild(env.gpa, ir.resolve(a.tok));
|
||||
node.appendStringChild(env.gpa, ir.resolve(a.region.start));
|
||||
return node;
|
||||
},
|
||||
// (mod_ty mod ty)
|
||||
.mod_ty => |a| {
|
||||
var node = sexpr.Expr.init(env.gpa, "mod_ty");
|
||||
node.appendStringChild(env.gpa, ir.resolve(a.tok));
|
||||
node.appendStringChild(env.gpa, ir.resolve(a.tok + 1));
|
||||
node.appendStringChild(env.gpa, ir.resolve(a.region.start));
|
||||
node.appendStringChild(env.gpa, ir.resolve(a.region.end));
|
||||
return node;
|
||||
},
|
||||
.tag_union => |a| {
|
||||
|
|
|
|||
|
|
@ -1804,18 +1804,17 @@ pub fn parseTypeAnno(self: *Parser, looking_for_args: TyFnArgs) IR.NodeStore.Typ
|
|||
.UpperIdent => {
|
||||
self.advance(); // Advance past UpperIdent
|
||||
if (self.peek() == .NoSpaceDotUpperIdent or self.peek() == .DotUpperIdent) {
|
||||
const second_ident = self.pos;
|
||||
self.advance(); // Advance past NoSpaceDotUpperIdent
|
||||
anno = self.store.addTypeAnno(.{ .mod_ty = .{
|
||||
.region = .{ .start = start, .end = start },
|
||||
.tok = start,
|
||||
.ty_ident = self.tok_buf.resolve_identifier(start),
|
||||
.mod_ident = self.tok_buf.resolve_identifier(start + 1),
|
||||
.region = .{ .start = start, .end = second_ident },
|
||||
.ty_ident = self.tok_buf.resolveIdentifier(start).?,
|
||||
.mod_ident = self.tok_buf.resolveIdentifier(second_ident).?,
|
||||
} });
|
||||
} else {
|
||||
anno = self.store.addTypeAnno(.{ .ty = .{
|
||||
.region = .{ .start = start, .end = start },
|
||||
.tok = start,
|
||||
.ident = self.tok_buf.resolve_identifier(start),
|
||||
.ident = self.tok_buf.resolveIdentifier(start).?,
|
||||
} });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -405,7 +405,9 @@ pub const TokenizedBuffer = struct {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn resolve_identifier(self: *TokenizedBuffer, token: Token.Idx) base.Ident.Idx {
|
||||
/// Loads the current token if it is an identifier.
|
||||
/// Otherwise returns null.
|
||||
pub fn resolveIdentifier(self: *TokenizedBuffer, token: Token.Idx) ?base.Ident.Idx {
|
||||
const tag = self.tokens.items(.tag)[@intCast(token)];
|
||||
const extra = self.tokens.items(.extra)[@intCast(token)];
|
||||
switch (tag) {
|
||||
|
|
@ -421,7 +423,7 @@ pub const TokenizedBuffer = struct {
|
|||
return extra.interned;
|
||||
},
|
||||
else => {
|
||||
std.debug.panic("not an identifier", .{});
|
||||
return null;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1621,12 +1621,12 @@ const Formatter = struct {
|
|||
try fmt.pushTokenText(v.tok);
|
||||
},
|
||||
.ty => |t| {
|
||||
try fmt.pushTokenText(t.tok);
|
||||
try fmt.pushTokenText(t.region.start);
|
||||
},
|
||||
.mod_ty => |t| {
|
||||
try fmt.pushTokenText(t.tok);
|
||||
try fmt.pushTokenText(t.region.start);
|
||||
try fmt.pushAll(".");
|
||||
try fmt.pushTokenText(t.tok + 1);
|
||||
try fmt.pushTokenText(t.region.end);
|
||||
},
|
||||
.tuple => |t| {
|
||||
region = t.region;
|
||||
|
|
|
|||
18
src/snapshots/fuzz_crash/fuzz_crash_018.txt
Normal file
18
src/snapshots/fuzz_crash/fuzz_crash_018.txt
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
~~~META
|
||||
description=fuzz crash
|
||||
type=file
|
||||
~~~SOURCE
|
||||
0 b:S
|
||||
.R
|
||||
~~~PROBLEMS
|
||||
PARSER: missing_header
|
||||
~~~TOKENS
|
||||
Int(1:1-1:2),LowerIdent(1:3-1:4),OpColon(1:4-1:5),UpperIdent(1:5-1:6),Newline(1:1-1:1),
|
||||
DotUpperIdent(2:1-2:3),EndOfFile(2:3-2:3),
|
||||
~~~PARSE
|
||||
(file
|
||||
(malformed_header (1:1-1:2) "missing_header")
|
||||
(type_anno (1:3-2:3)
|
||||
"b"
|
||||
(mod_ty "S" ".R")))
|
||||
~~~END
|
||||
Loading…
Add table
Add a link
Reference in a new issue