Ensure all NamedEntities have static types (#968)

This commit is contained in:
Geoff Romer
2021-12-07 12:27:47 -08:00
committed by GitHub
parent 652cd8c636
commit 021e83a4f4
4 changed files with 53 additions and 45 deletions
+13
View File
@@ -91,9 +91,22 @@ struct GenericBinding : public virtual AstNode, public NamedEntity {
auto type() const -> const Expression& { return *type_; }
auto type() -> Expression& { return *type_; }
// The static type of the binding. Cannot be called before typechecking.
auto static_type() const -> const Value& { return **static_type_; }
// Sets the static type of the binding. Can only be called once, during
// typechecking.
void set_static_type(Nonnull<const Value*> type) { static_type_ = type; }
// Returns whether the static type has been set. Should only be called
// during typechecking: before typechecking it's guaranteed to be false,
// and after typechecking it's guaranteed to be true.
auto has_static_type() const -> bool { return static_type_.has_value(); }
private:
std::string name_;
Nonnull<Expression*> type_;
std::optional<Nonnull<const Value*>> static_type_;
};
// The syntactic representation of a function declaration's return type.