本頁尚未翻譯,以下為英文原文。
#E0146: named some type used as its concrete type
Outside the module that declares type X = some Tr;, X is a type of its own that has only Tr: its concrete type cannot be named, and a value of another type is not an X. Keep the value as X (fields, let x: X, List<X> and parameters can all hold one), use it through Tr, and get new ones from the functions of X's module. Code that needs the concrete type goes in that module.
nabi
mod shapes {
pub type Count = some Display;
pub fn count() -> Count { 3 }
}
let n: i64 = shapes::count();
error[E0146]: mismatched types: `let n` expects `i64`, found `Count`: outside `shapes`, `Count` is opaque --> main.nabi:7:14 | 7 | let n: i64 = shapes::count(); | ^^^^^^^^^^^^^^^ | = help: only `shapes` sees what `Count` is: keep the value as `Count` and use it through its bounds, get one from `shapes::count`, or move this code into `shapes`
Keep it as Count:
nabi
mod shapes {
pub type Count = some Display;
pub fn count() -> Count { 3 }
}
let n: shapes::Count = shapes::count();
println(f"{n} shapes");
3 shapes
Related: E0040 mismatched types, E0145 named some type not defined by its module
Found a mistake? Edit this page on GitHub. Last updated