diff --git a/crates/aiken-lang/src/tipo/error.rs b/crates/aiken-lang/src/tipo/error.rs index 450a7218..1acbc454 100644 --- a/crates/aiken-lang/src/tipo/error.rs +++ b/crates/aiken-lang/src/tipo/error.rs @@ -259,7 +259,7 @@ You can use '{discard}' and numbers to distinguish between similar names. name: String, }, - #[error("I found a data type that has a function type in it. This is not allowed.\n")] + #[error("I found a type definition that has a function type in it. This is not allowed.\n")] #[diagnostic(code("illegal::function_in_type"))] #[diagnostic(help("Data-types can't hold functions. If you want to define method-like functions, group the type definition and the methods under a common namespace in a standalone module."))] FunctionTypeInData { @@ -267,6 +267,18 @@ You can use '{discard}' and numbers to distinguish between similar names. location: Span, }, + #[error("I found a type definition that has an unsupported type in it.\n")] + #[diagnostic(code("illegal::type_in_data"))] + #[diagnostic(help( + r#"Data-types can't contain type {type_info} because it can't be represented as PlutusData."#, + type_info = tipo.to_pretty(0).if_supports_color(Stdout, |s| s.red()) + ))] + IllegalTypeInData { + #[label] + location: Span, + tipo: Rc, + }, + #[error("I found a discarded expression not bound to a variable.\n")] #[diagnostic(code("implicit_discard"))] #[diagnostic(help( @@ -951,6 +963,7 @@ impl ExtraData for Error { | Error::DuplicateVarInPattern { .. } | Error::ExtraVarInAlternativePattern { .. } | Error::FunctionTypeInData { .. } + | Error::IllegalTypeInData { .. } | Error::ImplicitlyDiscardedExpression { .. } | Error::IncorrectFieldsArity { .. } | Error::IncorrectFunctionCallArity { .. } diff --git a/crates/aiken-lang/src/tipo/infer.rs b/crates/aiken-lang/src/tipo/infer.rs index 5dbea954..6adf8da9 100644 --- a/crates/aiken-lang/src/tipo/infer.rs +++ b/crates/aiken-lang/src/tipo/infer.rs @@ -545,6 +545,13 @@ fn infer_definition( location: *location, }); } + + if tipo.is_bls381_12_g1() || tipo.is_bls381_12_g2() || tipo.is_ml_result() { + return Err(Error::IllegalTypeInData { + location: *location, + tipo: tipo.clone(), + }); + } } }