Provide better errors on unknown type in cyclic definitions.

Let's consider the following case:

  ```
  type Var =
    Integer

  type Vars =
    List<Var>
  ```

  This incorrectly reports an infinite cycle; due to the inability to
  properly type-check `Var` which is also a dependent var of `Vars`. Yet
  the real issue here being that `Integer` is an unknown type.

  This commit also upgrades miette to 7.2.0, so that we can also display
  a better error output when the problem is actually a cycle.
This commit is contained in:
KtorZ
2024-08-06 11:45:42 +02:00
parent 1ae6640cd0
commit 91e0e2493a
17 changed files with 119 additions and 128 deletions

View File

@@ -26,7 +26,7 @@ hex = "0.4.3"
ignore = "0.4.20"
indexmap = "1.9.2"
itertools = "0.10.5"
miette = { version = "5.9.0", features = ["fancy"] }
miette.workspace = true
notify = "6.1.1"
num-bigint = "0.4.4"
owo-colors = { version = "3.5.0", features = ["supports-colors"] }

View File

@@ -19,7 +19,7 @@ pub enum Error {
#[label("invalid validator's boundary")]
location: Span,
#[source_code]
source_code: NamedSource,
source_code: NamedSource<String>,
},
#[error("Invalid or missing project's blueprint file.")]

View File

@@ -20,5 +20,6 @@ Schema {
source_code: NamedSource {
name: "",
source: "<redacted>",
language: None,
,
}

View File

@@ -20,5 +20,6 @@ Schema {
source_code: NamedSource {
name: "",
source: "<redacted>",
language: None,
,
}

View File

@@ -51,5 +51,6 @@ Schema {
source_code: NamedSource {
name: "",
source: "<redacted>",
language: None,
,
}

View File

@@ -16,7 +16,6 @@ use owo_colors::{
use std::{
fmt::{Debug, Display},
io,
ops::Deref,
path::{Path, PathBuf},
};
use zip::result::ZipError;
@@ -62,7 +61,7 @@ pub enum Error {
TomlLoading {
path: PathBuf,
src: String,
named: Box<NamedSource>,
named: Box<NamedSource<String>>,
location: Option<Span>,
help: String,
},
@@ -77,7 +76,7 @@ pub enum Error {
Parse {
path: PathBuf,
src: String,
named: NamedSource,
named: Box<NamedSource<String>>,
#[source]
error: Box<ParseError>,
},
@@ -86,7 +85,7 @@ pub enum Error {
Type {
path: PathBuf,
src: String,
named: NamedSource,
named: NamedSource<String>,
#[source]
error: tipo::error::Error,
},
@@ -156,7 +155,7 @@ impl Error {
errors.push(Error::Parse {
path: path.into(),
src: src.to_string(),
named: NamedSource::new(path.display().to_string(), src.to_string()),
named: NamedSource::new(path.display().to_string(), src.to_string()).into(),
error: error.into(),
});
}
@@ -451,11 +450,11 @@ impl Diagnostic for Error {
Error::ExportNotFound { .. } => None,
Error::Blueprint(e) => e.source_code(),
Error::NoDefaultEnvironment { .. } => None,
Error::Parse { named, .. } => Some(named),
Error::Parse { named, .. } => Some(named.as_ref()),
Error::Type { named, .. } => Some(named),
Error::StandardIo(_) => None,
Error::MissingManifest { .. } => None,
Error::TomlLoading { named, .. } => Some(named.deref()),
Error::TomlLoading { named, .. } => Some(named.as_ref()),
Error::Format { .. } => None,
Error::TestFailure { .. } => None,
Error::Http(_) => None,
@@ -538,7 +537,7 @@ pub enum Warning {
Type {
path: PathBuf,
src: String,
named: NamedSource,
named: NamedSource<String>,
#[source]
warning: tipo::error::Warning,
},

View File

@@ -762,7 +762,7 @@ where
.map(|(path, src, named, error)| Error::Parse {
path,
src,
named,
named: named.into(),
error,
})
.collect();
@@ -812,10 +812,6 @@ where
&mut self.data_types,
)?;
if name == "foo" {
println!("{:#?}", checked_module.ast);
}
if our_modules.contains(checked_module.name.as_str()) {
self.warnings.extend(warnings);
}

View File

@@ -20,5 +20,6 @@ Schema {
source_code: NamedSource {
name: "",
source: "<redacted>",
language: None,
,
}

View File

@@ -20,5 +20,6 @@ Schema {
source_code: NamedSource {
name: "",
source: "<redacted>",
language: None,
,
}