Add typechecking of type declarations (#984)

Also explicitly model the types of expressions whose values are class or choice types, and make those be the static_type of the type declaration. This ensures that the static_type of a NamedEntity consistently corresponds to the static type of an IdentifierExpression using that name.
This commit is contained in:
Geoff Romer
2021-12-13 16:19:52 -08:00
committed by GitHub
parent 90c58dae2b
commit fd45b089e9
5 changed files with 123 additions and 45 deletions
@@ -255,6 +255,14 @@ void Value::Print(llvm::raw_ostream& out) const {
out.write_escaped(cast<StringValue>(*this).value());
out << "\"";
break;
case Value::Kind::TypeOfClassType:
out << "typeof(" << cast<TypeOfClassType>(*this).class_type().name()
<< ")";
break;
case Value::Kind::TypeOfChoiceType:
out << "typeof(" << cast<TypeOfChoiceType>(*this).choice_type().name()
<< ")";
break;
}
}
@@ -350,6 +358,12 @@ auto TypeEqual(Nonnull<const Value*> t1, Nonnull<const Value*> t2) -> bool {
case Value::Kind::VariableType:
return &cast<VariableType>(*t1).binding() ==
&cast<VariableType>(*t2).binding();
case Value::Kind::TypeOfClassType:
return TypeEqual(&cast<TypeOfClassType>(*t1).class_type(),
&cast<TypeOfClassType>(*t2).class_type());
case Value::Kind::TypeOfChoiceType:
return TypeEqual(&cast<TypeOfChoiceType>(*t1).choice_type(),
&cast<TypeOfChoiceType>(*t2).choice_type());
default:
FATAL() << "TypeEqual used to compare non-type values\n"
<< *t1 << "\n"
@@ -420,6 +434,8 @@ auto ValueEqual(Nonnull<const Value*> v1, Nonnull<const Value*> v2,
case Value::Kind::ContinuationType:
case Value::Kind::VariableType:
case Value::Kind::StringType:
case Value::Kind::TypeOfClassType:
case Value::Kind::TypeOfChoiceType:
return TypeEqual(v1, v2);
case Value::Kind::NominalClassValue:
case Value::Kind::AlternativeValue: