diff --git a/sources/zweic/Analyzer.scala b/sources/zweic/Analyzer.scala index 91e5511..07e79a0 100755 --- a/sources/zweic/Analyzer.scala +++ b/sources/zweic/Analyzer.scala @@ -67,24 +67,24 @@ varScope.get(name.name) match { case Some(v) => Report.error(tree.pos, "Variable already defined " + name.name); + varScope case None => - val mv = VarSymbol(tree.pos, name.name, typ); - val et = analyzeExpr(varScope, expr); - varScope = varScope + name -> VarSymbol(); + val mt = analyzeType(typ); + checkSubtype(tree.pos, "Incompatible types", analyzeExpr(varScope, expr), mt); + varScope + name.name -> VarSymbol(tree.pos, name.name, mt); + } + + // ... � compl�ter ... + case Set(ident, expr) => + //TODO: this method is copied from lecture script, check if it's correct + varScope.get(ident.name) match { + case Some(v) => + ident.sym = v; + checkSubtype(tree.pos, "Incompatible types", analyzeExpr(varScope, expr), v.vartype); + case None => + Report.error(tree.pos, "Unknown variable " + ident.name); } varScope - - // ... � compl�ter ... - case Set(ident, expr) => - varScope.get(ident.name) match { - case Some(v) => - ident.sym = v; - if ( !analyzeExpr(varScope, expr).isSubtype(v.vartype) ) - Report.error(tree.pos, "Incompatible_types"); - case None => - Report.error(tree.pos, "Unknown variable " + ident.name); - } - varScope } // Analyze a type