Incorrect Typespec Generation for Fields with Custom or Parameterized Ecto Types in Strukt

Aperta
#20 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

  • #21 di @fishtreesugar — chiusa senza merge

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
elixir
Ambito
tooling

Direzione di ricerca

Inizia in lib/typespec.ex alle righe indicate, intorno alla gestione di value_type e defines_type?. Riproduci l’esempio Foo con Ecto.UUID e ispeziona la typespec generata mentre controlli la discussione del compilatore collegata. Il lavoro è completato quando i campi Ecto personalizzati e parametrizzati generano i loro tipi specifici invece di any().

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

Descrizione

Problem Description:

When defining a field with a custom Ecto type or a parameterized type in Strukt, the generated typespec for the field defaults to any() instead of the expected specific type (e.g., Ecto.UUID.t()). This issue may lead to less precise type checks and unexpected behaviors in development environments that rely on typespecs for static analysis or documentation purposes.

Example Code:

defmodule Foo do
  use Strukt
  
  defstruct do
    field :bar, Ecto.UUID
  end
end

Expected: The typespec for :bar should be Ecto.UUID.t().
Actual: The typespec for :bar is any().

Identified Issues:

Incorrect Handling of value_type:

The value_type in the typespec.ex function is not being correctly passed as a quoted expression. This results in the type not matching the expected case for processing.

Relevant code:
https://github.com/bitwalker/strukt/blob/b2b853256b0360599d67ca9f44b361c2a2a75beb/lib/typespec.ex#L56
https://github.com/bitwalker/strukt/blob/b2b853256b0360599d67ca9f44b361c2a2a75beb/lib/typespec.ex#L141

Failure in defines_type? Check:

The defines_type? function check always fails. This function, intended to verify if the current module defines a given type, is not feasible in current Elixir compiler. The docs of defines_type? say

Checks if the current module defines the given type (private, opaque or not).
This function is only available for modules being compiled.

Discussion related to this issue can be found here: Getting the @type module attribute
Relevant code: https://github.com/bitwalker/strukt/blob/b2b853256b0360599d67ca9f44b361c2a2a75beb/lib/typespec.ex#L152

Lingua principale
Elixir
Stelle
80
Fork
8
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 bitwalker/strukt

Tutte le issue di bitwalker/strukt

Issue simili

Altre issue su Elixir

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.