diff --git a/sources/zweic/Analyzer.scala b/sources/zweic/Analyzer.scala index 89c0427..741106d 100755 --- a/sources/zweic/Analyzer.scala +++ b/sources/zweic/Analyzer.scala @@ -89,7 +89,7 @@ val mt = analyzeType(typ); checkSubtype(tree.pos, "Incompatible types", analyzeExpr(varScope, expr), mt); val ms = VarSymbol(tree.pos, name.name, mt); - ident.sym = ms; + name.sym = ms; varScope + name.name -> ms; } @@ -148,30 +148,48 @@ case Select(expr, name) => val ct = analyzeExpr(varScope, expr); - ct.c.lookupField(name.name) match { - case Some(v) => + ct match { + case IClassType(c) => + c.lookupField(name.name) match { + case Some(v) => name.sym = v; v.fieldtype - case None => + case None => Report.error(tree.pos, "Unknown class variable " + name + " in " + ct); - IBadType + IBadType; + } + case _ => + Report.error(tree.pos, "Field '" + name.name + "' does not exist"); + IBadType; } case Call(expr, name, args) => - val ct = analyzeExpr(varScope, expr); //XXX: this implies checking if class exists - ct.c.lookupMethod(name.name) match { - case Some(v) => + val ct = analyzeExpr(varScope, expr); //XXX: this implies checking if class exists + + ct match { + case IClassType(c) => + c.lookupMethod(name.name) match { + case Some(v) => if (args.length != v.paramtypes.length) { - Report.error(tree.pos, "Wrong number of arguments for class method " + name + " in " + ct); - IBadType + Report.error(tree.pos, "Wrong number of arguments for class method " + name + " in " + ct); + IBadType } - if ( !args.map(x => analyzeExpr(varScope, x)).zip(v.paramtypes).forall(Tuple(a,b) => checkSubtype(tree.pos, "Incompatible types", a, b)) ) - IBadType + if ( !args.map(x => analyzeExpr(varScope, x)).zip(v.paramtypes) + .forall( x:Pair[Type,Type] => x._1.isSubtype(x._2)) ) { + Report.error(tree.pos, "Incompatible Types: \nrequired:" + v.allFields.foldLeft("", (a,b)=>a + b) + + "\nfound:" + args.foldRight("", (a,b)=>a + b) ); + IBadType; + } name.sym = v; v.restype - case None => + + case None => Report.error(tree.pos, "Unknown class method " + name + " in " + ct); IBadType + } + case _ => + Report.error(tree.pos, "Function '" + name.name + "' does not exist"); + IBadType; } case New(name, args) => @@ -181,8 +199,13 @@ Report.error(tree.pos, "Wrong number of arguments for class constructor in " + ct); IBadType } - if ( args.map(x => analyzeExpr(varScope, x)).zip(v.allFields).forall(Tuple(a,b) => checkSubtype(tree.pos, "Incompatible types", a, b)) ) - IBadType + if ( args.map(x => analyzeExpr(varScope, x)).zip(v.allFields) + .forall((a:Type, b:Type) => a.isSubtype(b)) ) { + Report.error(tree.pos, "Incompatible Types: \nrequired:" + v.allFields + + "\nfound:" + args); + IBadType; + } + name.sym = v; IClassType(v) case None => @@ -219,7 +242,7 @@ IIntType case If(cond, stata, statb) => - checkIntType(analyzeExpr(varScope, cond)) + checkIntType(analyzeExpr(varScope, cond)); analyzeExpr(varScope, stata).lub(analyzeExpr(varScope, statb)) case Block(stats, expr) =>