Changeset 3851

Show
Ignore:
Timestamp:
06/15/09 12:40:58 (5 months ago)
Author:
jrhil47
Message:

[typechecker] Added Typecase, As, AsIf? to Scala type checker; it now passes Compiled8. Changed a few Compiled6 tests to include return types.

Location:
trunk/ProjectFortress
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/ProjectFortress/compiler_tests/Compiled6.g.fss

    r3840 r3851  
    2020 
    2121object O 
    22   setter x(y:ZZ32) = y 
     22  setter x(y:ZZ32): () = y 
    2323end 
    2424 
  • trunk/ProjectFortress/compiler_tests/Compiled6.h.fss

    r3840 r3851  
    2020 
    2121object O 
    22   setter x(y:ZZ32) = () 
     22  setter x(y:ZZ32): () = () 
    2323  getter x(): String = "" 
    2424end 
  • trunk/ProjectFortress/compiler_tests/Compiled6.i.fss

    r3840 r3851  
    2020 
    2121object O 
    22   x(y: ZZ32) = () 
    23   x(y: ZZ32) = () 
     22  x(y: ZZ32): () = () 
     23  x(y: ZZ32): () = () 
    2424end 
    2525 
  • trunk/ProjectFortress/compiler_tests/Compiled6.m.fss

    r3840 r3851  
    2525 
    2626object O extends T 
    27   f(y:ZZ32) = () 
     27  f(y:ZZ32): () = () 
    2828end 
    2929 
  • trunk/ProjectFortress/compiler_tests/XXX6g.test

    r3762 r3851  
    1818compile 
    1919compile_err_equals=\ 
    20 ${STATIC_TESTS_DIR}/Compiled6.g.fss:22:3-22:\n\ 
    21 \ Setter declarations must return void.\n\ 
     20${STATIC_TESTS_DIR}/Compiled6.g.fss:22:26:\n\ 
     21\ Function body has type ZZ32, but declared return type is ().\n\ 
    2222File Compiled6.g.fss has 1 error.\n 
    2323compile_out_equals= 
  • trunk/ProjectFortress/compiler_tests/XXX6i.test

    r3783 r3851  
    1818compile 
    1919compile_err_equals=\ 
    20 ${STATIC_TESTS_DIR}/Compiled6.i.fss:22:3-17:\n\ 
    21 ${STATIC_TESTS_DIR}/Compiled6.i.fss:23:3-17:\n\ 
     20${STATIC_TESTS_DIR}/Compiled6.i.fss:22:3-21:\n\ 
     21${STATIC_TESTS_DIR}/Compiled6.i.fss:23:3-21:\n\ 
    2222\ There are multiple declarations of x with the same type: ZZ32 -> ()\n\ 
    2323File Compiled6.i.fss has 1 error.\n 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/ReturnTypeChecker.java

    r3845 r3851  
    2222import com.sun.fortress.exceptions.StaticError; 
    2323import com.sun.fortress.nodes.FnDecl; 
     24import com.sun.fortress.nodes.IdOrOp; 
     25import com.sun.fortress.nodes.IdOrOpOrAnonymousName; 
    2426import com.sun.fortress.nodes.LetFn; 
    2527import com.sun.fortress.nodes.Node; 
     
    4446  @Override 
    4547  public void forFnDecl(FnDecl that) { 
    46       if(that.getHeader().getReturnType().isNone()){ 
     48      IdOrOpOrAnonymousName name = that.getHeader().getName(); 
     49      boolean isCoercion = (name instanceof IdOrOp) ? 
     50          ((IdOrOp)name).getText().equals("coerce") : 
     51          false; 
     52      if (!isCoercion && that.getHeader().getReturnType().isNone()) { 
    4753        errors.add(StaticError.make("The Scala Typechecker requires return types on function:" + that.getUnambiguousName(), that)); 
    4854      } 
  • trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/STypeChecker.scala

    r3845 r3851  
    112112                               analyzer.extend(sparams, where), errors) 
    113113  } 
     114   
     115  private def extend(id: Id, typ: Type): STypeChecker = 
     116    extend(List[LValue](NodeFactory.makeLValue(id, typ))) 
    114117 
    115118  private def extendWithFunctions(methods: Relation[IdOrOpOrAnonymousName, JavaFunctionalMethod]) = 
     
    827830      val newContract = contract.map(c => newChecker.check(c)) 
    828831      val newBody = newChecker.checkExpr(body, returnType, "Function body", 
    829                                          "declared return") 
    830  
     832                                                           "declared return") 
    831833 
    832834      val newType = (returnType, getType(newBody)) match { 
    833         case (_, Some(bt)) if NodeUtil.isSetter(f) => 
    834           isSubtype(bt, Types.VOID, f, "Setter declarations must return void.") 
     835        case (Some(rt), _) if NodeUtil.isSetter(f) => 
     836          isSubtype(rt, Types.VOID, f, "Setter declarations must return void.") 
    835837          Some(Types.VOID) 
    836838        case (None, bt) => bt 
     
    16401642        case None => signal(id, errorMsg("Type of the variable '", id, "' not found.")); v 
    16411643      } 
     1644       
     1645    case STypecase(SExprInfo(span, paren, _), 
     1646                   bindIds, bindExpr, clauses, elseClause) => { 
     1647      if (bindIds.size != 1) 
     1648        NI.nyi("Typecase only supports a single identifier for now.") 
     1649       
     1650      // Make sure the bindId is not shadowing. 
     1651      val bindId = bindIds.first 
     1652      if (getTypeFromName(bindId).isDefined) { 
     1653        signal(bindId, "Cannot shadow name: %s".format(bindId)) 
     1654        return expr 
     1655      } 
     1656       
     1657      // Make sure the expr has a type. 
     1658      val checkedExpr = bindExpr.map(checkExpr). 
     1659        getOrElse(NI.nyi("Typecase currently must have a bound expression.")) 
     1660      val checkedType = getType(checkedExpr).getOrElse(return expr) 
     1661       
     1662      // Check each clause with the bound id having static type of the guard. 
     1663      def checkClause(c: TypecaseClause): TypecaseClause = c match {         
     1664        case STypecaseClause(info, List(matchType), body) => 
     1665          val checkedBody = 
     1666            this.extend(bindId, matchType). 
     1667            checkExpr(body).asInstanceOf[Block] 
     1668          STypecaseClause(info, List(matchType), checkedBody) 
     1669           
     1670        case _ => 
     1671          NI.nyi("Typecase only supports a single match type for now.") 
     1672      } 
     1673      val checkedClauses = clauses.map(checkClause) 
     1674      val clauseTypes = 
     1675        checkedClauses.map(c => getType(c.getBody).getOrElse(return expr)) 
     1676       
     1677      // Check the else clause with the new binding. 
     1678      val checkedElse = 
     1679        elseClause.map(e => this.extend(bindId, checkedType). 
     1680                              checkExpr(e).asInstanceOf[Block]) 
     1681      val elseType = checkedElse.map(getType(_).getOrElse(return expr)) 
     1682       
     1683      // Build union type of all clauses and else. 
     1684      val allTypes = elseType match { 
     1685        case Some(t) => Set(clauseTypes:_*) + t 
     1686        case _ => Set(clauseTypes:_*) 
     1687      } 
     1688      val unionType = NodeFactory.makeUnionType(allTypes) 
     1689       
     1690      STypecase(SExprInfo(span, paren, Some(unionType)), 
     1691                bindIds, 
     1692                Some(checkedExpr), 
     1693                checkedClauses, 
     1694                checkedElse) 
     1695    } 
     1696     
     1697    case SAsExpr(SExprInfo(span, paren, _), sub, typ) => { 
     1698      val checkedSub = checkExpr(sub, Some(typ), "Expression", "ascripted") 
     1699      SAsExpr(SExprInfo(span, paren, Some(typ)), checkedSub, typ) 
     1700    } 
     1701     
     1702    case SAsIfExpr(SExprInfo(span, paren, _), sub, typ) => { 
     1703      val checkedSub = checkExpr(sub, Some(typ), "Expression", "assumed") 
     1704      SAsIfExpr(SExprInfo(span, paren, Some(typ)), checkedSub, typ) 
     1705    } 
    16421706 
    16431707    case _ => throw new Error(errorMsg("Not yet implemented: ", expr.getClass)) 
  • trunk/ProjectFortress/src/com/sun/fortress/tests/unit_tests/FileTests.java

    r3844 r3851  
    972972                 || test_name.startsWith("Compiled4") 
    973973                 || test_name.startsWith("Compiled5") 
     974                 //|| test_name.startsWith("Compiled6") 
     975                // || test_name.startsWith("Compiled7") 
     976                // || test_name.startsWith("Compiled8") 
    974977                 ); 
    975978    }