Parse empty type params
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 56/100
Research direction
Start with src/parser.c at the linked type-parameter parsing code, then inspect lib/rbs/parser_aux.rb and the parse_type_params and parse_method_type entry points from the repro. Confirm whether [] should parse for both examples or only receive clearer errors, and verify that the chosen behavior is covered by the parser tests.
Written by the indexing model from the issue text.
Description
The two examples below fail to parse.
I think we should loosen the parsing requirements to allow empty type parameters, and then let the library user (Steep, Sorbet) decide how to handle that.
These cases are reachable if you're editing a file and want to rename a type parameter name. You would delete what's already there (leaving the [] empty), before you start typing the new name.
If we choose to leave this as an error in the RBS parser, it would be nice to at least have a more human-readable error messages.
Examples from Sorbet
Empty type parameters on a type (Sorbet.run):
#: []
# ^^ ❌ expected a token `pLBRACKET`
class NotActuallyGeneric
end
https://github.com/ruby/rbs/blob/e1373f0182fdfdc30d78be9b591ac188b8af7603/src/parser.c#L3341-L3345
Empty type parameters on a method (Sorbet.run):
#: [] (T) -> T
# ^^ ❌ expected a token `pARROW`
def identity(x) = x
Minimal repro
require "rbs"
RBS::Parser.parse_type_params "[]"
# /.../gems/rbs-4.0.2/lib/rbs/parser_aux.rb:43:in 'RBS::Parser._parse_type_params': a.rbs:1:0...1:2: # Syntax error: expected a token `pLBRACKET`, token=`[]` (pAREF_OPR) (RBS::ParsingError)
#
# []
# ^^
RBS::Parser.parse_method_type("[] () -> void")
# /.../gems/rbs-4.0.2/lib/rbs/parser_aux.rb:17:in 'RBS::Parser._parse_method_type': a.rbs:1:0...1:2: Syntax error: expected a token `pARROW`, token=`[]` (pAREF_OPR) (RBS::ParsingError)
#
# [] () -> void
# ^
- Dominant language
- Ruby
- Stars
- 2.2k
- Forks
- 263
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 64
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ruby/rbs
-
InlineParser: `@rbs @ivar` annotation is reported as unused unless it is the first thing in the class bodyPossibly taken @ksss claimed this 50 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
Maintainers usually reply within 1 day
Similar issues
-
needs verification
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 13 days
-
🐛 bug 👩💻 équipe CE 🧑🏭 entreprises
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
betagouv/conseillers-entreprises#4808 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
yosiat/panko_serializer#250 ·