Skip to content

Commit

Permalink
Merge pull request #821 from Shopify/uk-require-nothing-by-default
Browse files Browse the repository at this point in the history
Load nothing from Tapioca by default
  • Loading branch information
Morriar authored Feb 17, 2022
2 parents 0e3e4f2 + 9297b51 commit 280feb4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
4 changes: 0 additions & 4 deletions lib/tapioca.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,4 @@ class Error < StandardError; end
}.freeze, T::Hash[String, String])
end

require "tapioca/runtime/reflection"
require "tapioca/runtime/trackers"
require "tapioca/dsl/compiler"
require "tapioca/runtime/dynamic_mixin_compiler"
require "tapioca/version"
6 changes: 5 additions & 1 deletion lib/tapioca/internal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# frozen_string_literal: true

require "tapioca"
require "tapioca/runtime/reflection"
require "tapioca/runtime/trackers"
require "tapioca/runtime/dynamic_mixin_compiler"
require "tapioca/runtime/loader"
require "tapioca/sorbet_ext/generic_name_patch"
require "tapioca/sorbet_ext/fixed_hash_patch"
Expand All @@ -20,5 +23,6 @@
require "tapioca/gem/events"
require "tapioca/gem/listeners"
require "tapioca/gem/pipeline"
require "tapioca/static/requires_compiler"
require "tapioca/dsl/compiler"
require "tapioca/dsl/pipeline"
require "tapioca/static/requires_compiler"
42 changes: 30 additions & 12 deletions lib/tapioca/sorbet_ext/generic_name_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@ def type_template(variance = :invariant, fixed: nil, lower: T.untyped, upper: Ba
module Types
class Simple
module GenericPatch
def valid?(obj)
# Since `Tapioca::TypeVariable` is a `Module`, it will be wrapped by a
# `Simple` type. We want to always make type variable types valid, so we
# need to explicitly check that `raw_type` is a `Tapioca::TypeVariable`
# and return `true`
if defined?(Tapioca::TypeVariableModule) && Tapioca::TypeVariableModule === @raw_type
return true
end

obj.is_a?(@raw_type)
end

# This method intercepts calls to the `name` method for simple types, so that
# it can ask the name to the type if the type is generic, since, by this point,
# we've created a clone of that type with the `name` method returning the
Expand All @@ -88,9 +76,34 @@ def name
prepend GenericPatch
end
end

module Utils
module CoercePatch
def coerce(val)
if val.is_a?(Tapioca::TypeVariableModule)
val.coerce_to_type_variable
else
super
end
end
end

class << self
prepend(CoercePatch)
end
end
end

module Tapioca
class TypeVariable < ::T::Types::TypeVariable
def initialize(name, variance)
@name = name
super(variance)
end

attr_reader :name
end

# This is subclassing from `Module` so that instances of this type will be modules.
# The reason why we want that is because that means those instances will automatically
# get bound to the constant names they are assigned to by Ruby. As a result, we don't
Expand Down Expand Up @@ -153,6 +166,11 @@ def serialize
serialized
end

sig { returns(Tapioca::TypeVariable) }
def coerce_to_type_variable
TypeVariable.new(name, @variance)
end

private

sig do
Expand Down

0 comments on commit 280feb4

Please sign in to comment.