Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.83 KB | None | 0 0
  1. case eq : Equals => {
  2.           val primTypes : List[Type] = List(TString, TInt, TBoolean, TIntArr, TUnit)
  3.           // We want to consider all types, so we need to append class types through anyObject
  4.           val lhsType : Type = tcExpr(eq.lhs, (primTypes ::: List(anyObject)): _*)
  5.           lhsType match {
  6.             case TObject(classSymbol) => {
  7.               tcExpr(eq.rhs, anyObject)
  8.               TBoolean
  9.             }
  10.             case prim if primTypes.contains(prim) => {
  11.               tcExpr(eq.rhs, prim)
  12.               TBoolean
  13.             }
  14.             case _ => {
  15.               val rhsType : Type = tcExpr(eq.rhs)
  16.               fatal("Type error: Equality operator requires compatible types, but found types: "
  17.               + lhsType + " and " + rhsType)
  18.               TError
  19.             }
  20.           }
  21.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement