`lean --deps` panics in `HeaderSyntax.imports` on a header that does not parse

Aperta
#16,464 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
Mezza giornata
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Ambito
cli, compilers

Direzione di ricerca

Start with Lean.Elab.parseImports, which passes the result of Parser.parseHeader to headerToImports without checking its messages, then with HeaderSyntax.imports in Lean/Elab/Import.lean, where the unreachable! at line 40 is hit. Reproduce with printf 'import\n' > W.lean && lean --deps W.lean. Done when the header's parse error is reported with a non-zero exit and no panic, for import, import Init., import 3, a tab before import, and a lone carriage return.

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

Descrizione

Description

lean --deps panics on any file whose header doesn't parse, then goes on to look up a module named [anonymous]. lean on the same file reports the parse error as a normal message.

Steps to Reproduce
printf 'import\n' > W.lean
lean --deps W.lean

Expected behavior: the header's parse error, as lean W.lean reports it (W.lean:2:0: error: unexpected end of input; expected identifier), with a non-zero exit and no panic.

Actual behavior:

PANIC at Lean.Elab.HeaderSyntax.imports Lean.Elab.Import:40:13: unreachable code has been reached
backtrace:
…
<toolchain>/lib/lean/Init.olean
<toolchain>/lib/lean/Init.olean
unknown module prefix '[anonymous]'

No directory '[anonymous]' or file '[anonymous].olean' in the search path entries:
<toolchain>/lib/lean

The same happens for every header error I tried: import Init., import 3, a tab before an import ("tabs are not allowed"), and an isolated carriage return.

Cause

Lean.Elab.parseImports passes the header that Parser.parseHeader returns to headerToImports without checking the returned messages for errors. On the error-recovered syntax, neither pattern in HeaderSyntax.imports matches, so it reaches unreachable!. printImports (--deps) and printImportSrcs (--src-deps) both go through it. So does any program that calls parseImports to read a header's imports and its end position.

Versions

Lean (version 4.34.1, aarch64-unknown-linux-gnu, commit 5045d0056413266e57c625dcd7c365b10e377c52, Release), on Linux.

Impact

A tool that reads a module's imports with parseImports or lean --deps, as a build driver does before passing them through --setup, has to check the header's messages itself first.

Lingua principale
Lean
Stelle
10.3k
Fork
1.1k
Merge medio
19h 8m
PR unite (30g)
421

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 leanprover/lean4

Tutte le issue di leanprover/lean4

Issue simili

Altre issue su CLI

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.