Skip to content

Instantly share code, notes, and snippets.

@fbs
Created March 9, 2020 18:00
Show Gist options
  • Save fbs/02328da1ba9a61127ef896da9a9c4317 to your computer and use it in GitHub Desktop.
Save fbs/02328da1ba9a61127ef896da9a9c4317 to your computer and use it in GitHub Desktop.
diff --git a/src/ast/semantic_analyser.cpp b/src/ast/semantic_analyser.cpp
index cb637ca..baa4b11 100644
--- a/src/ast/semantic_analyser.cpp
+++ b/src/ast/semantic_analyser.cpp
@@ -1026,8 +1026,29 @@ void SemanticAnalyser::visit(Binop &binop)
auto get_int_literal = [](const auto expr) -> long {
return static_cast<ast::Integer*>(expr)->n;
};
- auto left = binop.left;
- auto right = binop.right;
+ auto &left = binop.left;
+ auto &right = binop.right;
+
+ if (left->type.size != right->type.size)
+ {
+ if (right->is_literal)
+ {
+ std::cout << "Adusting rsh size\n";
+ right->type.size = left->type.size;
+ }
+ else if (left->is_literal)
+ {
+ std::cout << "Adusting lsh size\n";
+ left->type.size = right->type.size;
+ }
+
+ else {
+ std::stringstream buf;
+ buf << "Type size mismatch: '" << binop.left->type << "' and '"
+ << binop.right->type << "', please insert a cast";
+ error(buf.str(), binop.loc);
+ }
+ }
// First check if operand signedness is the same
if (lsign != rsign) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment