Skip to content

Commit 389c98a

Browse files
committed
Fix unary type priority
Fix #645
1 parent b65a0d3 commit 389c98a

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

crates/emmylua_code_analysis/src/compilation/test/type_check_test.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,21 @@ mod test {
1717
"#,
1818
));
1919
}
20+
21+
#[test]
22+
fn test_issue_645() {
23+
let mut ws = VirtualWorkspace::new();
24+
25+
assert!(ws.check_code_for(
26+
DiagnosticCode::ParamTypeNotMatch,
27+
r#"
28+
--- @alias Dir -1|1
29+
30+
---@param d Dir
31+
local function foo(d) end
32+
33+
foo(1)
34+
"#,
35+
));
36+
}
2037
}

crates/emmylua_parser/src/grammar/doc/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
lexer::LuaDocLexerState,
55
parser::{CompleteMarker, LuaDocParser, MarkerEventContainer},
66
parser_error::LuaParseError,
7+
UNARY_TYPE_PRIORITY,
78
};
89

910
use super::{expect_token, if_token_bump, parse_description};
@@ -60,7 +61,7 @@ fn parse_sub_type(p: &mut LuaDocParser, limit: i32) -> ParseResult {
6061
let range = p.current_token_range();
6162
let m = p.mark(LuaSyntaxKind::TypeUnary);
6263
p.bump();
63-
match parse_sub_type(p, 0) {
64+
match parse_sub_type(p, UNARY_TYPE_PRIORITY) {
6465
Ok(_) => {}
6566
Err(err) => {
6667
p.push_error(LuaParseError::doc_error_from(

crates/emmylua_parser/src/kind/lua_type_operator_kind.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub const PRIORITY: &[PriorityTable] = &[
3030
PriorityTable { left: 6, right: 6 }, // Sub
3131
];
3232

33+
pub const UNARY_TYPE_PRIORITY: i32 = 7;
34+
3335
impl LuaTypeBinaryOperator {
3436
pub fn get_priority(&self) -> &PriorityTable {
3537
&PRIORITY[*self as usize]

crates/emmylua_parser/src/kind/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub use lua_operator_kind::{BinaryOperator, UnaryOperator, UNARY_PRIORITY};
1111
pub use lua_syntax_kind::LuaSyntaxKind;
1212
pub use lua_token_kind::LuaTokenKind;
1313
pub use lua_type_operator_kind::{
14-
LuaTypeBinaryOperator, LuaTypeTernaryOperator, LuaTypeUnaryOperator,
14+
LuaTypeBinaryOperator, LuaTypeTernaryOperator, LuaTypeUnaryOperator, UNARY_TYPE_PRIORITY,
1515
};
1616
pub use lua_version::{LuaVersionCondition, LuaVersionNumber};
1717
pub use lua_visibility_kind::VisibilityKind;

0 commit comments

Comments
 (0)