Skip to content

Commit 1675b16

Browse files
committed
feat: add trait instantiatbility check
1 parent 8ee6982 commit 1675b16

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ enum_dispatch = "0.3"
3535
threadpool = {version = "1.8", optional = true}
3636
dunce = "1.0"
3737
toml = "0.7"
38-
ariadne = "0.2"
38+
ariadne = {version = "0.3", features = []}
3939
dyn-fmt = "0.3"
4040
petgraph = "0.6"
4141
kagari = { path = "./kagari" }

src/ast/ctx.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use super::node::macro_nodes::MacroNode;
88
use super::node::node_result::NodeResult;
99
use super::node::NodeEnum;
1010
use super::node::TypeNode;
11+
use super::node::TypeNodeEnum;
1112
use super::plmod::CompletionItemWrapper;
1213
use super::plmod::GlobType;
1314
use super::plmod::GlobalVar;
@@ -482,6 +483,25 @@ impl<'a, 'ctx> Ctx<'a> {
482483
}
483484
}
484485
let (st_pltype, st_value) = self.auto_deref(ori_pltype, ori_value, builder);
486+
if let PLType::Trait(t) = &*target_pltype.borrow() {
487+
for f in t.list_trait_fields().iter() {
488+
if let TypeNodeEnum::Func(fu) = &*f.typenode {
489+
if fu.generics.is_some() {
490+
return Err(target_range.new_err(ErrorCode::THE_TARGET_TRAIT_CANNOT_BE_INSTANTIATED)
491+
.add_label(
492+
target_range,
493+
self.get_file(),
494+
format_label!("trait type `{}`", t.get_name()),
495+
)
496+
.add_label(
497+
f.range,
498+
t.get_path(),
499+
format_label!("the method `{}` of trait `{}` has generic params, which makes it uninstantiatable",&f.name, t.get_name()),
500+
).add_to_ctx(self));
501+
}
502+
}
503+
}
504+
}
485505
match (&*target_pltype.borrow(), &*st_pltype.clone().borrow()) {
486506
(PLType::Trait(t), PLType::Struct(st)) => {
487507
return self.cast_implable(

src/ast/diag.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ define_diag!(
163163
INVALID_STRUCT_INIT = "invalid struct initialization",
164164
REDUNDANT_COMMA = "REDUNDANT comma",
165165
GENERIC_NOT_ALLOWED_IN_TRAIT_METHOD = "generic not allowed in trait method",
166+
THE_TARGET_TRAIT_CANNOT_BE_INSTANTIATED = "the target trait type cannot be instantiated",
166167
);
167168

168169
define_diag! {

test/main.pi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub fn main() i64 {
9696
let bbbb = 1;
9797
let re = ttt.eq(&bbbb);
9898
println!(re);
99+
let hashtest:Hash = "a";
99100
return 0;
100101
}
101102

0 commit comments

Comments
 (0)