mame / typeprof-playground

5 stars 0 forks source link

Internal Server Error with certain inputs #4

Open connorshea opened 4 years ago

connorshea commented 4 years ago

Issue

I'm not really sure why, but this causes an internal server error:

ruby

# frozen_string_literal: true
module Faker
  class Base
    class << self
      def flexible(key)
        @flexible_key = key
      end
    end
  end
end

module Faker
  class Game < Base
    flexible :game

    class << self
      ##
      # Produces the name of a video game.
      #
      # @return [String]
      #
      # @example
      #   Faker::Game.title #=> "Half-Life 2"
      #
      # @faker.version 1.9.4
      def title
        fetch('game.title')
      end

      ##
      # Produces the name of a video game genre.
      #
      # @return [String]
      #
      # @example
      #   Faker::Game.genre #=> "Real-time strategy"
      #
      # @faker.version 1.9.4
      def genre
        fetch('game.genre')
      end

      ##
      # Produces the name of a video game console or platform.
      #
      # @return [String]
      #
      # @example
      #   Faker::Game.platform #=> "Nintendo Switch"
      #
      # @faker.version 1.9.4
      def platform
        fetch('game.platform')
      end
    end
  end
end

rbs

module Faker
  class Game < Base
    def self.title: -> String
    def self.genre: -> String
    def self.platform: -> String
  end
end

output

# Classes
module Faker
  class Base
    def self.flexible : (:game) -> :game
  end

  class Game < Base
    self.@flexible_key : :game
    def self.title : -> untyped
    def self.genre : -> untyped
    def self.platform : -> untyped
  end
end

## Version info:
##   * Ruby: 2.7.2
##   * RBS: 0.17.0
##   * TypeProf: 0.5.4
mame commented 4 years ago

Thank you for playing TypeProf!

The reason why it fails is because there is no declaration of Base in RBS. It works by adding an empty declaration of Base:

module Faker
  class Base
  end
  class Game < Base
    def self.title: -> String
    def self.genre: -> String
    def self.platform: -> String
  end
end

Currently, TypeProf requires that the input RBS is self-contained. In this case, TypeProf may assume an undefined superclass is a class name.

Anyway, TypeProf should not raise a raw exception against any input. I'll fix the issue in the next version. Thank you again!