LoginSignup
0
0

More than 5 years have passed since last update.

既存のクラスと同じ名前のcaseをもつenumを定義する

Last updated at Posted at 2015-10-25

ちょっと合理性が思いつかないのでバグの類だと思うんだけど、こういうのがコンパイルエラーになる。

indirect enum Type {
  case Var(String)       // ここで Use of Undeclared Type 'String' とか言われる
  case String
  case Int
  case List(Type)
  case Bool
  case Function(Type, Type)
}

どうも列挙型を定義するときに既存の型名と同じ名前のcaseがあるとダメみたい。case名を変えるか、型パラメータにする。

indirect enum TypeBase<T> {
  case Var(T)
  case String
  case Int
  case Bool
  case List(TypeBase<T>)
  case Function(TypeBase<T>, TypeBase<T>)
}

typealias Type = TypeBase<String>

Xcode 7.0.1のPlaygroundで確認してる。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0