Questions tagged [sorbet]
Sorbet is a fast, powerful type checker designed for Ruby.
150
questions
0
votes
0
answers
15
views
Sorbet lsp segmentation fault after enabling vs codium extension. Server closes and will not restart. Sorbet will not work?
I am trying to get Sorbet extension to work with Vs Codium. I just recently ran into this issue after having another unrelated issue I believe but was related to bundle.
After I did my bundle install ...
0
votes
0
answers
22
views
Sorbet can't locate Gemfile
Using VSCode with Ruby-LSP, I've been struggling to get it working. When Sorbet tries to start I get the following error.
Running Sorbet LSP with:
bundle exec srb typecheck --lsp
Could not locate ...
0
votes
1
answer
20
views
How do I get VS Code Sorbet to find the right bundler version?
The error I'm seeing in the output:
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.3.25) required by your ...
3
votes
0
answers
21
views
Sorbet type-checking freezes in my Rails 6 project with latest sorbet and tapioca versions
We have a Rails 6 project and running into problems getting Sorbet typechecking to work. We have been following the adoption guide and getting stuck at Step 3 with no debug output or errors.
These are ...
0
votes
1
answer
112
views
Bundler can't resolve a version for sorbet-static that matches my current platform; Found sorbet-static ... that did not match the current platform
On an intel Mac running Ventura 13.3, I am getting this problem when trying to bundle install :
Found sorbet-static (0.5.9019-x86_64-linux),
sorbet-static (0.5.9019-x86_64-linux) that did not match ...
2
votes
0
answers
45
views
How to type a subclass of DelegateClass with Sorbet?
I want to type a class which inherits DelegateClass(SomeClass). The method Kernel#DelegateClass receives a class, and returns a new class which delegates methods to the given class instance (docs).
...
1
vote
0
answers
35
views
Rails: How to work with serialize attributes and Sorbet
I can't find any examples of how to deal with attributes that are serialized columns.
class MyClass < ApplicationRecord
serialize :related_pages, Array
end
In this case, it is an Array of String ...
1
vote
0
answers
21
views
Tapioca failure with sparsam and boost dlopen error
I'm curious about next steps to investigate this issue. I wonder whether this is an issue with the version of boost used when building the native extensions for the sparsam gem?
/Users/username/...
2
votes
1
answer
58
views
uninitialized constant Array::Elem
The following recommended solution from the Sorbet FAQ results in uninitialized constant Array::Elem during execution (bundle exec srb tc runs fine):
# typed: true
class Array
extend T::Sig
sig {...
0
votes
1
answer
175
views
How to avoid using Sorbet's T.must when the code flow already knows that value is not nil?
I'm using Sorbet on a Rails project and I have a method that does a calculation on a nilable property.
def age
return unless dob && dob.year > 1900
now = Time.now.utc.to_date
now....
0
votes
1
answer
160
views
How to setup sorbet to work with a Rails 7 application?
note: I'm not using and I want to know if it is possible without sorbet-rails.
I'm trying to add sorbet to an existing/standard Rails 7 application.
I followed the instruction here: https://sorbet.org/...
1
vote
0
answers
63
views
How to run tapioca when files changes in my Ruby project?
I have write a custom dsl compiler in my Ruby project with Sorbet.
Every time I create or edit a file that uses this custom dsl I have to run
bin/tapioca dsl in the console.
How I could automatize ...
1
vote
0
answers
59
views
Autogenerate/sync Typescript Types and Ruby Types [closed]
Ruby has types through RBS or Sorbet. What's the best way to autogenerate/sync Typescript Types with Ruby Types?
The pain point that I am trying to solve is avoiding bugs caused by misalignments ...
0
votes
0
answers
66
views
Sorbet warning: method redefined when using Structs in tests
Recently, while working on a gem that interacts with Sorbet T::Struct, I started to see this warning in my test suite:
(eval):1: warning: method redefined; discarding old __t_props_generated_serialize
...
1
vote
1
answer
97
views
Sorbet does not check runtime type of an arg if it's an array
I have the following code that you can just copy&paste locally and run it as a single file:
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'sorbet-runtime'
end
...
3
votes
1
answer
150
views
How to configure Sorbet with rspec?
I have a simple test but the describe keyword is not working in Sorbet tests.
The error I'm receiving on these methods:
Method `describe` does not exist on `T.class_of(<root>)`7003
RSpec....
2
votes
1
answer
125
views
Require Elem when using Sorbet RBI
I want to extend the standard Array with a new instance method but I keep getting a runtime error about the type_member not being found.
The definition looks like this.
class Array
extend T::Sig
...
2
votes
1
answer
194
views
Define method signature for passthrough method defined in super class in Ruby with Sorbet
We're considering adopting Sorbet and I wanted to know if it's possible to define the signature of the following method. This is a common pattern we use: there is an abstract Service class that has a ...
0
votes
1
answer
81
views
Properly typing a multiline string in ruby with sorbet
I'm adopting Sorbet into a project and I can't understand how should I type the following constant:
RETRIEVE_FILE_URL_QUERY = <<~QUERY.freeze
query($input: ID!) {
node(id: $input) {
... on ...
1
vote
1
answer
125
views
Tapioca shims for Rails Engines?
I have a Rails application using Rails engines and packwerk to organize the code. Each of the packwrk component has an engine.rb file, which sometimes looks like this:
module Foobar
class Engine <...
1
vote
0
answers
170
views
How to define the same struct using Sorbet?
all!
I want to define a generic result data type, which is a union of a generic success type and a generic failure type.
The same thing in TS looks like this:
type Success<T> = {
value: T
}
...
0
votes
1
answer
101
views
Error 5067 - How can I bypass it and implement Sorbet on my project?
I use rails-observers gem and I just can't run srb tc without errors...
app/models/supplier_observer.rb:3: The super class ActiveRecord::Observer of SupplierObserver does not derive from Class https://...
0
votes
1
answer
110
views
How can I make Sorbet see an ignored class?
I have just installed Sidekiq into my Rails project. Unfortunately, Sorbet doesn't like it. For some reason it thinks that Sidekiq::Job is a class instead of a module and so it keeps throwing the ...
2
votes
1
answer
102
views
Tell sorbet about a Sequel Model's inheritance hierarchy
I'm trying to apply typing to a repo that uses the Sequel gem. It's got a non-standard Ruby syntax for a particular use case: initializing a model when a table name doesn't follow a convention
Example:...
1
vote
0
answers
267
views
In sorbet can you use the return type of one object as the typing for the argument of another?
Take the following line of code:
csv_text = T.let(File.read(csv_address), String)
@csv = T.let(CSV.parse(csv_text), T.any(CSV::Table,
T::Array[T::Array[T....
1
vote
1
answer
74
views
Sorbet and tapioca unable to detect a class from require_relative
I have a file in a Sinatra app, config/environment.rb:
class Environment
def self.test?
RACK_ENV == 'test'
end
and another one api/middleware/error_handler.rb
require_relative '../../config/...
2
votes
1
answer
107
views
Sorbet Error - The Super class UserBase of UserEmbeds does not derive from Class
I've been very interested in adopting sorbet for strict types in ruby, but while installing it on my existing codebase i've run into a wall that I dont understand
I get the following error when ...
0
votes
0
answers
68
views
bundle exec tapioca init for sorbet throws error
I'm trying to adopt sorbet into my pre-existing project. I get to the 3rd step of their adoption instructions. I can't get bundle exec tapioca init to run. Anyone have any ideas?
bundler: failed to ...
1
vote
1
answer
523
views
how to type strong params in rails api / sorbet / tapioca
i'm trying to start a new project where i play with typing and i'm having a hard time getting the basic API stuff to work.
here is the code from my controller:
# typed: strict
module Api
module V1
...
1
vote
1
answer
58
views
Rubymine Unused Method Highlighting
Is it possible for Rubymine to highlight unused methods if you aren't using a typing system like ruby 3 or sorbet has?
0
votes
1
answer
31
views
Exception::raise(): Unimplemented Parser Node: EmptyElse
When running srb init in a Rails app I get the following:
Generating /tmp/d20220723-3779490-paqj5l/reflection.rbi with 6784 modules and 142 aliases
Printing your code's symbol table into /tmp/...
1
vote
1
answer
278
views
Any way to instantiate a generic type in Sorbet? (calling new on type_member)
I'd like to instantiate an instance of the generic type I pass in. For example,
module MyModule
extend T::Sig
extend T::Generic
class << self
extend T::Sig
extend T::Generic
...
1
vote
0
answers
46
views
Sorbet unable to resolve constant -- even though its in the rbi
Just updated mongoid.rbi from 6 to 7. Started getting a ton of errors like the following:
components/assets/models/assets/stats_timestamp.rb:5: Unable to resolve constant Timestamps https://srb.help/...
1
vote
1
answer
110
views
Is there an equivalent in Sorbet to Typescript's Pick?
A colleague is trying to write a method that returns a subset of fields outlined in a T::Struct, and we're wondering if there is a Sorbet analog to Typescript's Pick, where only properties of an ...
1
vote
1
answer
112
views
Running into transient NoMethodError errors with T.cast in production
we’re running into transient NoMethodError errors in code paths using T.cast on our production services. Here are some notable facts
Is happening in sorbet-runtime as of version 0.5.10012
It only ...
0
votes
1
answer
55
views
Rails AggregateRoot "on" handlers not detected as instance methods
In Rails event store, AggregateRoot has DSL methods that result in blocks with this shape:
class X
extend AggregateRoot::OnDSL
class MyEvent < RailsEventStore::Event; end
on MyEvent do |...
0
votes
1
answer
149
views
Integrating sorbet with paper-trail
When I try and add a has_paper_trail on any of my models to include versioning for objects created, Sorbet throws the following error:
app/models/model_name.rb:22: Method `has_paper_trail` does not ...
1
vote
1
answer
62
views
What runtime code can I write to extract the type notations as defined by Sorbet, to display to the user?
Is there a way to inspect the type notations in ruby/sorbet?
I actually want to display those values in a form somewhere and instead of hardcoding in values like "this can be nil or a String"...
0
votes
1
answer
255
views
Sorbet: Too many arguments provided for method Proc0#call
I am trying to pass an argument to Proc0#call but Sorbet fails:
foo do |data|
# Do stuff
end
sig { params(block: T.proc.void).void }
def foo(&block)
x = { foo: :bar }
block.call(x)
end
...
3
votes
0
answers
158
views
Sorbet LSP sublime text read typed: false
So I'm using LSP and Sorbet with Sublime Text 3. I have an issue in my RSpec files that have typed: false in them. The engine spits out tons of type errors:
5:3 error Method `it` does not exist on ...
1
vote
1
answer
154
views
How to handle memoization with nil values with Sorbet?
I have this method:
def current_organization
return @current_organization if defined?(@current_organization)
subdomain = request.subdomain.to_s
return @current_organization = nil if ...
1
vote
2
answers
474
views
How do I reuse a T::Struct structure in another T::Struct
I have the following:
class Coordinate < T::Struct
const :x, Integer
const :y, Integer
end
class ThreeDCoordinate < T::Struct
const :x, Integer
const :y, Integer
const :z, Integer
end
...
1
vote
1
answer
92
views
Why does changing Bundlers installation directory cause Sorbet to fall over?
For reasons to do with my CI setup I've needed to change the location where I install my Ruby gems from the default location to: bundle config set path 'vendor/bundle'
However, as soon as I do so, ...
0
votes
1
answer
80
views
Should I expect Sorbet to perform platform-dependently?
I've run into some trouble when changing the image I've been using for my CI process on CircleCI. I changed the image when I upgraded my version of Ruby.
bundle exec srb tc is running fine locally ...
4
votes
0
answers
259
views
How can I override Generated Attribute Methods in Ruby on Rails when using Sorbet?
I have a model with a jsonb column. This column accepts only json objects. Sorbet correctly generates the .rbi file containing the following:
module PushedContent::GeneratedAttributeMethods
sig { ...
2
votes
1
answer
133
views
Sorbet overrides URI from Kernel
I have method as below
sig do
params(uri: URI).returns(String)
end
def get(uri)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.start
response = http....
1
vote
1
answer
131
views
Can invalid signature errors ever trigger at runtime if code has been statically checked by Sorbet?
I was looking through the list of Sorbet runtime errors from the docs. It seems to me that "Errors from invalid sig procs" and "Errors from invalid sigs" would be caught by the ...
2
votes
1
answer
578
views
How can I resolve sorbet error: "Constants must have type annotations with T.let when specifying # typed: strict"?
This is similar to my question in How can I resolve sorbet error: "Use of undeclared variable"?, but for constants.
I am experimenting with adding sorbet type information to my gem, pdf-...
1
vote
1
answer
295
views
Resolving "code is unreachable" in sorbet
I maintain the pdf-reader ruby gem, and I'm experimenting with static type checking via sorbet.
I have a particular source file that's currently typed: false, and I'd like to change it to typed: true. ...
3
votes
1
answer
1k
views
Confusion on when to use T.let vs. T.cast
Based on: https://sorbet.org/docs/type-assertions
In my mind, T.cast seems like a more powerful version of T.let. T.cast(expr, type) forces Sorbet to accept expr as type, even if expr cannot be ...