Better error when using ';' instead of ',' when declaring struct

This commit is contained in:
Olivier Goffart 2023-07-24 12:04:38 +02:00 committed by Olivier Goffart
parent c1dce3e2a1
commit 37f11e566b
2 changed files with 19 additions and 0 deletions

View file

@ -41,6 +41,11 @@ pub fn parse_type_object(p: &mut impl Parser) {
p.expect(SyntaxKind::Identifier);
p.expect(SyntaxKind::Colon);
parse_type(&mut *p);
if p.peek().kind() == SyntaxKind::Semicolon {
p.error("Expected ','. Use ',' instead of ';' to separate fields in a struct");
p.consume();
continue;
}
if !p.test(SyntaxKind::Comma) {
break;
}

View file

@ -0,0 +1,14 @@
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
export struct TetronimoBrettData {
fliesen: [FlieseData];
// ^error{Expected ','. Use ',' instead of ';' to separate fields in a struct}
zeilenzahl: { x: int; };
// ^error{Expected ','. Use ',' instead of ';' to separate fields in a struct}
// ^^error{Expected ','. Use ',' instead of ';' to separate fields in a struct}
y: int;
// ^error{Expected ','. Use ',' instead of ';' to separate fields in a struct}
};
// ^error{Extra semicolon. Remove this semicolon}