Parse empty type params

Aperta
#2,993 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
56/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
c, ruby
Ambito
compilers

Direzione di ricerca

Inizia da src/parser.c nel codice collegato per il parsing dei parametri di tipo, poi esamina lib/rbs/parser_aux.rb e gli entry point parse_type_params e parse_method_type della riproduzione. Conferma se [] debba essere analizzato per entrambi gli esempi o se debba soltanto produrre errori più chiari, e verifica che il comportamento scelto sia coperto dai test del parser.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
#  ^
Lingua principale
Ruby
Stelle
2.2k
Fork
263
Merge medio
1g 20h
PR unite (30g)
64

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/rbs

Tutte le issue di ruby/rbs

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.