mame / typeprof-playground

5 stars 0 forks source link

typeprof-playground gives error on Either class when seeing behavior #10

Open stevenproctor opened 2 years ago

stevenproctor commented 2 years ago

Issue

Trying the typeprof playground to see how typeprof would work with an untyped Either class. The output section is left over from the starting example

ruby


    # Either Type
    # Holds a Left(x) or a Right(y)
    class Either

      class << self
        # Either.Left
        # Represents an error in a calculation flow
        class Left
          def initialize(lval)
            @lval = lval
          end

          def bind
            self
          end

          alias flatmap bind

          def map
            self
          end

          def or_else
            result = yield @lval
            Left.new(result)
          end

          def left_of?(klass)
            @lval.is_a? klass
          end

          def right_of?(_klass)
            false
          end

          def inspect
            "Either::Left<#{@lval.inspect}>"
          end
        end

        # Either.Right
        # Represents the result value in a calculation flow
        class Right
          def initialize(rval)
            @rval = rval
          end

          def bind(&fun)
            result = fun.call(@rval)
            if result.is_a?(Right) || result.is_a?(Left)
              result
            else
              Right.new(result)
            end
          end

          alias flatmap bind

          def map
            result = yield @rval
            Right.new(result)
          end

          def or_else
            self
          end

          def left_of?(_klass)
            false
          end

          def right_of?(klass)
            @rval.is_a? klass
          end

          def inspect
            "Either::Right<#{@rval.inspect}>"
          end
        end
        def left(value)
          Left.new(value)
        end

        def right(value)
          Right.new(value)
        end
      end

      private_class_method :new
    end

rbs

output

# TypeProf 0.15.0

# Errors
test.rb:6: [error] failed to resolve overload: String#+

# Classes
class Object
  private
  def hello_message: (User user) -> String
  def type_error_demo: (User user) -> untyped
end

## Version info:
##   * Ruby: 3.1.2
##   * RBS: 1.3.1
##   * TypeProf: 0.15.0