Skip to content

Commit 51c1753

Browse files
committed
update typecheck: generic type match
1 parent e45282d commit 51c1753

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

crates/emmylua_code_analysis/src/diagnostic/test/return_type_mismatch_test.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,4 +470,30 @@ mod tests {
470470
"#
471471
));
472472
}
473+
474+
#[test]
475+
fn test_generic_type_1() {
476+
let mut ws = VirtualWorkspace::new();
477+
ws.def(
478+
r#"
479+
---@class Range: Observable<integer>
480+
---@class Observable<T>
481+
482+
---@return Range
483+
function newRange()
484+
end
485+
"#,
486+
);
487+
assert!(ws.check_code_for(
488+
DiagnosticCode::ReturnTypeMismatch,
489+
r#"
490+
491+
---@return Observable<integer>
492+
function range()
493+
return newRange()
494+
end
495+
496+
"#
497+
));
498+
}
473499
}

crates/emmylua_code_analysis/src/semantic/type_check/generic_type.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use crate::{
66
};
77

88
use super::{
9-
check_general_type_compact, type_check_fail_reason::TypeCheckFailReason,
10-
type_check_guard::TypeCheckGuard, TypeCheckResult,
9+
check_general_type_compact, check_ref_type_compact,
10+
type_check_fail_reason::TypeCheckFailReason, type_check_guard::TypeCheckGuard, TypeCheckResult,
1111
};
1212

1313
pub fn check_generic_type_compact(
@@ -53,6 +53,12 @@ pub fn check_generic_type_compact(
5353
LuaMemberOwner::Element(range.clone()),
5454
check_guard.next_level()?,
5555
),
56+
LuaType::Ref(_) | LuaType::Def(_) => check_ref_type_compact(
57+
db,
58+
&source_generic.get_base_type_id(),
59+
compact_type,
60+
check_guard.next_level()?,
61+
),
5662
_ => Err(TypeCheckFailReason::TypeNotMatch),
5763
}
5864
}

0 commit comments

Comments
 (0)