0

I mean:

class Foo; end
class Bar < Foo; end
class Cux < Foo; end

Is it possible to restrict type of the variable to classes inheriting from Foo without unions, something like x : Foo+?

Vitalii Elenhaupt
  • 7,146
  • 3
  • 27
  • 43
ClassyPimp
  • 715
  • 7
  • 20

1 Answers1

1

Maybe using a type restriction?

@x : Foo
asterite
  • 2,906
  • 1
  • 14
  • 14
  • Weird, previously on carc.in I tried that - and it raised of type mismatch. Now it works. BTW thanks for your great job on Crystal! How's new compiler going? – ClassyPimp Feb 09 '16 at 06:38
  • 1
    We abandoned the new compiler for now. We'll start by making the current compiler have the semantics we want. Once that is done we won't be breaking any more code and we can focus (slowly) on optimizing the compiler or maybe rewriting it from scratch, or rewrite some sub-systems. – asterite Feb 10 '16 at 03:56