From 28a82755d230e6aa31e4241b9610a977be902fd8 Mon Sep 17 00:00:00 2001 From: Joel Drapper Date: Thu, 28 Nov 2024 20:12:10 +0000 Subject: [PATCH] Fix autoloading issues --- lib/literal/transforms.rb | 36 ++++++++++++++--------------- lib/literal/types.rb | 18 +++++++-------- lib/literal/types/any_type.rb | 6 ++--- lib/literal/types/boolean_type.rb | 8 +++---- lib/literal/types/falsy_type.rb | 8 +++---- lib/literal/types/json_data_type.rb | 11 ++++----- lib/literal/types/never_type.rb | 6 ++--- lib/literal/types/truthy_type.rb | 13 ++++++----- lib/literal/types/tuple_type.rb | 2 +- lib/literal/types/void_type.rb | 6 ++--- 10 files changed, 57 insertions(+), 57 deletions(-) diff --git a/lib/literal/transforms.rb b/lib/literal/transforms.rb index 81d0e9e..07e9761 100644 --- a/lib/literal/transforms.rb +++ b/lib/literal/transforms.rb @@ -7,18 +7,18 @@ ceil: Integer, chr: String, denominator: Integer, - even?: Literal::Types::BooleanType, + even?: Literal::Types::BooleanType::Instance, floor: Integer, hash: Integer, inspect: String, integer?: true, magnitude: Integer, - negative?: Literal::Types::BooleanType, + negative?: Literal::Types::BooleanType::Instance, next: Integer, numerator: Integer, - odd?: Literal::Types::BooleanType, + odd?: Literal::Types::BooleanType::Instance, ord: Integer, - positive?: Literal::Types::BooleanType, + positive?: Literal::Types::BooleanType::Instance, pred: Integer, round: Integer, size: Integer, @@ -29,17 +29,17 @@ to_r: Rational, to_s: String, truncate: Integer, - zero?: Literal::Types::BooleanType, + zero?: Literal::Types::BooleanType::Instance, }, String => { - ascii_only?: Literal::Types::BooleanType, + ascii_only?: Literal::Types::BooleanType::Instance, bytesize: Integer, capitalize: String, chomp: String, chop: String, downcase: String, dump: String, - empty?: Literal::Types::BooleanType, + empty?: Literal::Types::BooleanType::Instance, hash: Integer, inspect: String, length: Integer, @@ -53,7 +53,7 @@ swapcase: String, to_str: String, upcase: String, - valid_encoding?: Literal::Types::BooleanType, + valid_encoding?: Literal::Types::BooleanType::Instance, }, Numeric => { to_i: Integer, @@ -63,13 +63,13 @@ Array => { size: Integer, length: Integer, - empty?: Literal::Types::BooleanType, + empty?: Literal::Types::BooleanType::Instance, sort: Array, to_a: Array, to_ary: Array, }, Hash => { - empty?: Literal::Types::BooleanType, + empty?: Literal::Types::BooleanType::Instance, inspect: String, keys: Array, length: Integer, @@ -80,7 +80,7 @@ values: Array, }, Set => { - empty?: Literal::Types::BooleanType, + empty?: Literal::Types::BooleanType::Instance, inspect: String, length: Integer, size: Integer, @@ -91,17 +91,17 @@ abs: Float, ceil: Integer, floor: Integer, - nan?: Literal::Types::BooleanType, - negative?: Literal::Types::BooleanType, - positive?: Literal::Types::BooleanType, + nan?: Literal::Types::BooleanType::Instance, + negative?: Literal::Types::BooleanType::Instance, + positive?: Literal::Types::BooleanType::Instance, round: Integer, to_i: Integer, to_s: String, truncate: Integer, - zero?: Literal::Types::BooleanType, + zero?: Literal::Types::BooleanType::Instance, }, Symbol => { - empty?: Literal::Types::BooleanType, + empty?: Literal::Types::BooleanType::Instance, inspect: String, length: Integer, size: Integer, @@ -111,7 +111,7 @@ Range => { begin: Object, end: Object, - exclude_end?: Literal::Types::BooleanType, + exclude_end?: Literal::Types::BooleanType::Instance, first: Object, last: Object, max: Object, @@ -121,7 +121,7 @@ to_s: String, }, Regexp => { - casefold?: Literal::Types::BooleanType, + casefold?: Literal::Types::BooleanType::Instance, inspect: String, source: String, to_s: String, diff --git a/lib/literal/types.rb b/lib/literal/types.rb index 6e8b643..23d9c1e 100644 --- a/lib/literal/types.rb +++ b/lib/literal/types.rb @@ -29,7 +29,7 @@ module Literal::Types CallableType = InterfaceType.new(:call).freeze LambdaType = ConstraintType.new(Proc, lambda?: true).freeze - NilableBooleanType = NilableType.new(BooleanType).freeze + NilableBooleanType = NilableType.new(BooleanType::Instance).freeze NilableCallableType = NilableType.new(CallableType).freeze NilableJSONDataType = NilableType.new(JSONDataType).freeze NilableLambdaType = NilableType.new(LambdaType).freeze @@ -37,11 +37,11 @@ module Literal::Types # Matches any value except `nil`. Use `_Any?` or `_Void` to match any value including `nil`. def _Any - AnyType + AnyType::Instance end def _Any? - VoidType + VoidType::Instance end # Matches if the value is an `Array` and all the elements match the given type. @@ -58,7 +58,7 @@ def _Array?(...) # Matches if the value is `true` or `false`. def _Boolean - BooleanType + BooleanType::Instance end # Nilable version of `_Boolean` @@ -128,7 +128,7 @@ def _Enumerable?(...) # Matches *"falsy"* values (`nil` and `false`). def _Falsy - FalsyType + FalsyType::Instance end # Matches if the value is a `Float` and matches the given constraints. @@ -211,7 +211,7 @@ def _Intersection?(...) # Ensures the value is valid JSON data (i.e. it came from JSON.parse). def _JSONData - JSONDataType + JSONDataType::Instance end # Nilable version of `_JSONData` @@ -242,7 +242,7 @@ def _Map?(...) # Never matches any value. def _Never - NeverType + NeverType::Instance end # Matches if the value is either `nil` or the given type. @@ -316,7 +316,7 @@ def _Symbol?(...) # Matches *"truthy"* values (anything except `nil` and `false`). def _Truthy - TruthyType + TruthyType::Instance end # Matches if the value is an `Array` and each element matches the given types in order. @@ -344,6 +344,6 @@ def _Union?(...) end def _Void - VoidType + VoidType::Instance end end diff --git a/lib/literal/types/any_type.rb b/lib/literal/types/any_type.rb index b25689c..55d3db3 100644 --- a/lib/literal/types/any_type.rb +++ b/lib/literal/types/any_type.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true # @api private -class Literal::Types::AnyTypeClass +class Literal::Types::AnyType + Instance = new.freeze + include Literal::Type def inspect @@ -18,5 +20,3 @@ def >=(other) freeze end - -Literal::Types::AnyType = Literal::Types::AnyTypeClass.new.freeze diff --git a/lib/literal/types/boolean_type.rb b/lib/literal/types/boolean_type.rb index dfaeb82..2e624e1 100644 --- a/lib/literal/types/boolean_type.rb +++ b/lib/literal/types/boolean_type.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true # @api private -class Literal::Types::BooleanTypeClass +class Literal::Types::BooleanType + Instance = new.freeze + include Literal::Type def inspect @@ -14,7 +16,7 @@ def ===(value) def >=(other) case other - when true, false, Literal::Types::BooleanTypeClass + when true, false, Literal::Types::BooleanType true else false @@ -23,5 +25,3 @@ def >=(other) freeze end - -Literal::Types::BooleanType = Literal::Types::BooleanTypeClass.new.freeze diff --git a/lib/literal/types/falsy_type.rb b/lib/literal/types/falsy_type.rb index 19a5f4f..efc8558 100644 --- a/lib/literal/types/falsy_type.rb +++ b/lib/literal/types/falsy_type.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true # @api private -class Literal::Types::FalsyTypeClass +class Literal::Types::FalsyType + Instance = new.freeze + include Literal::Type def initialize @@ -18,7 +20,7 @@ def ===(value) def >=(other) case other - when Literal::Types::FalsyTypeClass, nil, false + when Literal::Types::FalsyType, nil, false true else false @@ -27,5 +29,3 @@ def >=(other) freeze end - -Literal::Types::FalsyType = Literal::Types::FalsyTypeClass.new.freeze diff --git a/lib/literal/types/json_data_type.rb b/lib/literal/types/json_data_type.rb index 534e009..fbc7b7a 100644 --- a/lib/literal/types/json_data_type.rb +++ b/lib/literal/types/json_data_type.rb @@ -1,11 +1,10 @@ # frozen_string_literal: true # @api private -class Literal::Types::JSONDataTypeClass - include Literal::Type +class Literal::Types::JSONDataType + Instance = new.freeze - # This needs to be defined here so it can be referenced in the COMPATIBLE_TYPES constant. - Literal::Types::JSONDataType = Literal::Types::JSONDataTypeClass.new.freeze + include Literal::Type COMPATIBLE_TYPES = Set[ Integer, @@ -14,8 +13,8 @@ class Literal::Types::JSONDataTypeClass true, false, nil, - Literal::Types::BooleanType, - Literal::Types::JSONDataType + Literal::Types::BooleanType::Instance, + Instance ].freeze def inspect = "_JSONData" diff --git a/lib/literal/types/never_type.rb b/lib/literal/types/never_type.rb index e70cb0d..796c6b3 100644 --- a/lib/literal/types/never_type.rb +++ b/lib/literal/types/never_type.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true # @api private -class Literal::Types::NeverTypeClass +class Literal::Types::NeverType + Instance = new.freeze + include Literal::Type def inspect @@ -23,5 +25,3 @@ def >=(other) freeze end - -Literal::Types::NeverType = Literal::Types::NeverTypeClass.new.freeze diff --git a/lib/literal/types/truthy_type.rb b/lib/literal/types/truthy_type.rb index e702665..87ddf47 100644 --- a/lib/literal/types/truthy_type.rb +++ b/lib/literal/types/truthy_type.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true # @api private -class Literal::Types::TruthyTypeClass +class Literal::Types::TruthyType + Instance = new.freeze include Literal::Type def inspect @@ -13,15 +14,15 @@ def ===(value) end def >=(other) + return false if other == Literal::Types::FalseyType + case other - when Literal::Types::TruthyType, true - true - else + when false, nil false + else + true end end freeze end - -Literal::Types::TruthyType = Literal::Types::TruthyTypeClass.new.freeze diff --git a/lib/literal/types/tuple_type.rb b/lib/literal/types/tuple_type.rb index 080715c..ae67e60 100644 --- a/lib/literal/types/tuple_type.rb +++ b/lib/literal/types/tuple_type.rb @@ -38,7 +38,7 @@ def record_literal_type_errors(context) while i < len actual = context.actual[i] if !(expected = @types[i]) - context.add_child(label: "[#{i}]", expected: Literal::Types::NeverType, actual:) + context.add_child(label: "[#{i}]", expected: Literal::Types::NeverType::Instance, actual:) elsif !(expected === actual) context.add_child(label: "[#{i}]", expected:, actual:) end diff --git a/lib/literal/types/void_type.rb b/lib/literal/types/void_type.rb index ccfb1d8..048a68d 100644 --- a/lib/literal/types/void_type.rb +++ b/lib/literal/types/void_type.rb @@ -1,7 +1,9 @@ # frozen_string_literal: true # @api private -class Literal::Types::VoidTypeClass +class Literal::Types::VoidType + Instance = new.freeze + include Literal::Type def inspect @@ -18,5 +20,3 @@ def >=(_) freeze end - -Literal::Types::VoidType = Literal::Types::VoidTypeClass.new.freeze