forked from sorbet/sorbet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…4829) * Allow binding blocks to attached_class and self_type * Add test case for trying to bind a proc's parameter * Look up attached class member on the singleton class * Prevent proc bind from being used in non-block arguments * Add more test cases and handle method level bind to attached_class
- Loading branch information
Showing
11 changed files
with
241 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# typed: true | ||
|
||
class TypeTemplate | ||
extend T::Sig | ||
extend T::Generic | ||
|
||
Elem = type_template | ||
|
||
sig { params(block: T.proc.bind(Elem).void).void } | ||
# ^^^^^^^^^^^^^^^^^ error: Malformed `bind`: Can only bind to simple class names | ||
def self.before_create(&block); end | ||
end | ||
|
||
class TypeMember | ||
extend T::Sig | ||
extend T::Generic | ||
|
||
Elem = type_member | ||
|
||
sig { params(block: T.proc.bind(Elem).void).void } | ||
# ^^^^^^^^^^^^^^^^^ error: Malformed `bind`: Can only bind to simple class names | ||
def before_create(&block); end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# typed: true | ||
|
||
class Base | ||
extend T::Sig | ||
|
||
sig { params(block: T.proc.bind(T.attached_class).void).void } | ||
def self.before_create(&block); end | ||
|
||
before_create do | ||
T.reveal_type(self) # error: Revealed type: `Base` | ||
end | ||
end | ||
|
||
Base.before_create do | ||
T.reveal_type(self) # error: Revealed type: `Base` | ||
end | ||
|
||
class Model < Base | ||
before_create do | ||
T.reveal_type(self) # error: Revealed type: `Model` | ||
|
||
does_exist | ||
does_not_exist # error: Method `does_not_exist` does not exist on `Model` | ||
end | ||
|
||
def does_exist; end | ||
end | ||
|
||
Model.before_create do | ||
T.reveal_type(self) # error: Revealed type: `Model` | ||
|
||
does_exist | ||
does_not_exist # error: Method `does_not_exist` does not exist on `Model` | ||
end | ||
|
||
class BadBinds | ||
extend T::Sig | ||
|
||
sig {params(it: T.proc.bind(T.attached_class).void).void} | ||
# ^^ error: Using `bind` is not permitted here | ||
def self.non_block_argument(it); end | ||
|
||
sig {returns(T.proc.bind(T.attached_class).void)} | ||
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Using `bind` is not permitted here | ||
def self.attached_class_return | ||
T.unsafe(nil) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# typed: true | ||
|
||
module Mixin | ||
extend T::Sig | ||
|
||
sig { params(block: T.proc.bind(T.self_type).void).void } | ||
def foo(&block); end | ||
end | ||
|
||
class IncludesMixin | ||
include Mixin | ||
|
||
def does_exist; end | ||
|
||
def bar | ||
foo do | ||
T.reveal_type(self) # error: Revealed type: `IncludesMixin` | ||
|
||
does_exist | ||
does_not_exist # error: Method `does_not_exist` does not exist on `IncludesMixin` | ||
end | ||
end | ||
end | ||
|
||
IncludesMixin.new.foo do | ||
T.reveal_type(self) # error: Revealed type: `IncludesMixin` | ||
|
||
does_exist | ||
does_not_exist # error: Method `does_not_exist` does not exist on `IncludesMixin` | ||
end | ||
|
||
class Base | ||
extend T::Sig | ||
|
||
sig { params(block: T.proc.bind(T.self_type).void).void } | ||
def self.foo(&block); end | ||
|
||
sig { params(block: T.proc.bind(T.self_type).void).void } | ||
def instance_foo(&block); end | ||
end | ||
|
||
class Model < Base | ||
def self.does_exist; end | ||
def does_exist; end | ||
|
||
foo do | ||
T.reveal_type(self) # error: Revealed type: `T.class_of(Model)` | ||
|
||
does_exist | ||
does_not_exist # error: Method `does_not_exist` does not exist on `T.class_of(Model)` | ||
end | ||
|
||
def bar | ||
instance_foo do | ||
T.reveal_type(self) # error: Revealed type: `Model` | ||
|
||
does_exist | ||
does_not_exist # error: Method `does_not_exist` does not exist on `Model` | ||
end | ||
end | ||
end | ||
|
||
Model.foo do | ||
T.reveal_type(self) # error: Revealed type: `T.class_of(Model)` | ||
|
||
does_exist | ||
does_not_exist # error: Method `does_not_exist` does not exist on `T.class_of(Model)` | ||
end | ||
|
||
Model.new.instance_foo do | ||
T.reveal_type(self) # error: Revealed type: `Model` | ||
|
||
does_exist | ||
does_not_exist # error: Method `does_not_exist` does not exist on `Model` | ||
end |