Skip to content

Commit a53788f

Browse files
committed
[Sema] error out on trait object reference comparison
1 parent 15c147b commit a53788f

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/sema.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,16 @@ Sema::resolveBinaryOperator(res::Context &ctx,
363363
if (rhsTy->getAs<res::StructType>() || rhsTy->getAs<res::TypeParamType>())
364364
typeError = true;
365365

366-
for (auto &&ty : {lhsTy, rhsTy})
366+
for (auto &&ty : {lhsTy, rhsTy}) {
367+
if (ty->getAs<res::AnyTraitType>()) {
368+
typeError = true;
369+
continue;
370+
}
371+
367372
if (auto *ptr = ty->getAs<res::PointerType>();
368373
ptr && ptr->getPointeeType()->getAs<res::AnyTraitType>())
369374
typeError = true;
375+
}
370376

371377
if (!typeError) {
372378
lhs = hardenTypeIfNeeded(ctx, lhs, rhsTy);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: compiler %s 2>&1 -res-dump | filecheck %s
2+
trait A {}
3+
4+
extension number : A {}
5+
6+
fn foo(a: &any A) {
7+
// CHECK: [[# @LINE + 1 ]]:5: error: incompatible operands to binary operator ('any A' and 'any A')
8+
a == a;
9+
}
10+
11+
fn main() {}

0 commit comments

Comments
 (0)