AndreVanDelft / scala

The SubScript extension to the Scala programming language
http://www.subscript-lang.org/
12 stars 1 forks source link

Strange behaviour of match{} expressions #8

Open AndreVanDelft opened 10 years ago

AndreVanDelft commented 10 years ago

TemplateNode: matching on T_n_ary_op (and T_1_ary_op) does not work; therefore FTTB those classes have their own implementation of kindAsString (see the comments in the file)

anatoliykmetyuk commented 10 years ago

Can you please specify more precisely where does it not work? As I can see, matching on T_n_ary_op works perfectly on line 339 of ScriptExecutor.scala.

AndreVanDelft commented 10 years ago

E.g. here, a T_1_aryop is matched by "case ":

  def kindAsString(t: TemplateNode): String = 
    t match {
      // matching on T_n_ary_op (and T_1_ary_op) does not work;
      // therefore FTTB those classes have their own implementation of kindAsString
      case T_1_ary_op(kind: String, _) => kind
      case T_n_ary_op(kind: String, _) => kind

      case T_code_normal            (_) => "{}"
      ...
      case _ => getClass.getName
    }

So what is the problem?

anatoliykmetyuk commented 10 years ago

The match

case T_n_ary_op(kind: String, _) =>

won't work, 'cause second argument is vararg. Varargs should be matched as follows:

case T_n_ary_op(kind: String, _*) =>

I'll try to get rid of auxiliary "kind" methods a bit later.