Error if a public enum has a variant which contains private type
Prevents a case of a public type containing a private type.
Fixes
@@ -1483,6 +1483,13 @@ pub fn infer_module(
};
if public {
fields.push((constructor.name.clone(), typ.clone()));
+
+ if let Some(leaked) = typ.find_private_type() {
+ return Err(Error::PrivateTypeLeak {
+ meta: constructor.meta.clone(),
+ leaked,
+ });
+ }
};
env.insert_variable(
constructor.name.clone(),
@@ -4044,6 +4051,20 @@ pub fn x() { id(1, 1.0) }
},
},
},
+ Case {
+ src: r#"external type PrivateType
+ pub enum LeakType =
+ | Variant(PrivateType)"#,
+ error: Error::PrivateTypeLeak {
+ meta: Meta { start: 90, end: 110 },
+ leaked: Type::App {
+ args: vec![],
+ public: false,
+ module: vec![],
+ name: "PrivateType".to_string(),
+ },
+ },
+ },
];
for Case { src, error } in cases.into_iter() {
