diff --git a/sources/zweic/Analyzer.scala b/sources/zweic/Analyzer.scala index 8718328..a4dc9c8 100755 --- a/sources/zweic/Analyzer.scala +++ b/sources/zweic/Analyzer.scala @@ -39,7 +39,8 @@ Report.error(tree.pos, "Class already defined: " + name) case None => val cs = ClassSymbol(tree.pos, name.name, None); - classScope(name.name) = cs; + classScope = classScope + name.name -> cs; + //classScope(name.name) = cs; members.foreach(x => analyzeMember(cs,x)) } case ClassDef(name, extend, members) => @@ -48,7 +49,8 @@ Report.error(tree.pos, "Class already defined: " + name); case None => val cs = ClassSymbol(tree.pos, name.name, classScope.get(extend.get.name)); - classScope(name.name) = cs; + classScope = classScope + name.name -> cs; + //classScope(name.name) = cs; members.foreach(x => analyzeMember(cs,x)) } } @@ -68,6 +70,8 @@ case MethodDef(name, args, rtype, expr) => var myVarScope = emptyVarScope; + myVarScope = myVarScope + "this" -> VarSymbol(ownerClass.pos, "this", IClassType(ownerClass)); + for ( val x <- ownerClass.allFields ) myVarScope = myVarScope + x.name -> x.asInstanceOf[VarSymbol]; val paramtypes = for ( val f <- args ) yield { @@ -78,7 +82,6 @@ } val rt = analyzeType(rtype); - checkSubtype(tree.pos, "Return type mismatch", analyzeExpr(myVarScope, expr), rt); name.sym = MethodSymbol(tree.pos, name.name, paramtypes, rt); ownerClass.lookupMethod(name.name) match { @@ -87,6 +90,8 @@ case None => ownerClass.enterNewMethod(name.sym.asInstanceOf[MethodSymbol]); } + + checkSubtype(tree.pos, "Return type mismatch", analyzeExpr(myVarScope, expr), rt); } // Analyze a statement @@ -144,7 +149,7 @@ name.sym = c; IClassType(c) case None => - Report.error(tree.pos, "Class " + name + " is unknown"); + Report.error(tree.pos, "type " + name + " is unknown"); IBadType } } @@ -217,12 +222,12 @@ Report.error(tree.pos, "Wrong number of arguments for class constructor in " + ct); IBadType } - if ( args.map(x => analyzeExpr(varScope, x)).zip(v.allFields.map(y => y.fieldtype)) + if ( !args.map(x => analyzeExpr(varScope, x)).zip(v.allFields.map(y => y.fieldtype)) .forall( x:Pair[Type, Type] => x._1.isSubtype(x._2)) ) { Report.error(tree.pos, "Incompatible Types: \nrequired:" + v.allFields + "\nfound:" + args); IBadType; - } + } name.sym = v; IClassType(v)