this repo has no description

Remove deprecated type import syntax

+67 -373
-9
compiler-core/src/analyse.rs
··· 186 186 187 187 // Generate warnings for unused items 188 188 let unused_imports = env.convert_unused_to_warnings(); 189 - env.emit_warnings_for_deprecated_type_imports(); 190 189 191 190 // Remove imported types and values to create the public interface 192 191 // Private types and values are retained so they can be used in the language ··· 213 212 module_types_constructors: types_constructors, 214 213 module_values: values, 215 214 accessors, 216 - ambiguous_imported_items, 217 215 .. 218 216 } = env; 219 - 220 - let type_only_unqualified_imports = ambiguous_imported_items 221 - .into_iter() 222 - .filter(|(_, item)| item.type_ && !item.value) 223 - .map(|(name, _)| name) 224 - .collect(); 225 217 226 218 Ok(ast::Module { 227 219 documentation, ··· 236 228 origin, 237 229 unused_imports, 238 230 package: package.clone(), 239 - type_only_unqualified_imports, 240 231 }, 241 232 }) 242 233 }
+30 -73
compiler-core/src/analyse/imports.rs
··· 1 - use std::collections::HashSet; 2 - 3 1 use ecow::EcoString; 4 2 5 3 use crate::{ 6 4 ast::{Import, SrcSpan, UnqualifiedImport}, 7 5 build::Origin, 8 - type_::{ 9 - self, EntityKind, Environment, Error, LayerUsage, ModuleInterface, ValueConstructorVariant, 10 - }, 6 + type_::{self, EntityKind, Environment, Error, ModuleInterface, ValueConstructorVariant}, 11 7 warning::TypeWarningEmitter, 12 8 }; 13 9 ··· 62 58 self.check_src_does_not_import_test(module_info, location, imported_module_name.clone())?; 63 59 self.register_module(import, module_info)?; 64 60 65 - // TODO: remove this when we remove the old syntax 66 - let mut types = HashSet::with_capacity(import.unqualified_types.len()); 67 61 // Insert unqualified imports into scope 68 62 for type_ in &import.unqualified_types { 69 - self.register_unqualified_type(type_, module_info, &mut types)?; 63 + self.register_unqualified_type(type_, module_info)?; 70 64 } 71 65 for value in &import.unqualified_values { 72 - self.register_unqualified_value(value, module_info, &mut types)?; 66 + self.register_unqualified_value(value, module_info)?; 73 67 } 74 68 Ok(()) 75 69 } ··· 78 72 &mut self, 79 73 import: &UnqualifiedImport, 80 74 module: &ModuleInterface, 81 - imported_types: &mut HashSet<EcoString>, 82 75 ) -> Result<(), Error> { 83 76 self.check_if_deprecated_bit_string(import, module, import.location); 84 77 ··· 106 99 import.location, 107 100 ); 108 101 109 - let _ = imported_types.insert(imported_name.clone()); 110 - 111 102 Ok(()) 112 103 } 113 104 ··· 115 106 &mut self, 116 107 import: &UnqualifiedImport, 117 108 module: &ModuleInterface, 118 - imported_types: &mut HashSet<EcoString>, 119 109 ) -> Result<(), Error> { 120 110 self.check_if_deprecated_bit_string(import, module, import.location); 121 111 122 112 let import_name = &import.name; 123 113 let location = import.location; 124 114 let used_name = import.as_name.as_ref().unwrap_or(&import.name); 125 - let mut type_imported = false; 126 - let mut value_imported = false; 127 - let mut variant = None; 128 115 129 116 // Register the unqualified import if it is a value 130 - if let Some(value) = module.get_public_value(import_name) { 131 - self.environment.insert_variable( 132 - used_name.clone(), 133 - value.variant.clone(), 134 - value.type_.clone(), 135 - true, 136 - value.deprecation.clone(), 137 - ); 138 - variant = Some(&value.variant); 139 - value_imported = true; 140 - } 141 - 142 - // Register the unqualified import if it is a type constructor 143 - if !imported_types.contains(used_name) { 144 - if let Some(typ) = module.get_public_type(import_name) { 145 - self.environment.insert_type_constructor( 117 + let variant = match module.get_public_value(import_name) { 118 + Some(value) => { 119 + self.environment.insert_variable( 146 120 used_name.clone(), 147 - typ.clone().with_location(location), 148 - )?; 149 - type_imported = true; 121 + value.variant.clone(), 122 + value.type_.clone(), 123 + true, 124 + value.deprecation.clone(), 125 + ); 126 + &value.variant 127 + } 128 + None => { 129 + return Err(Error::UnknownModuleValue { 130 + location, 131 + name: import_name.clone(), 132 + module_name: module.name.clone(), 133 + value_constructors: module.public_value_names(), 134 + }); 150 135 } 151 - } 136 + }; 152 137 153 - if value_imported && type_imported { 154 - self.environment.init_usage( 138 + match variant { 139 + &ValueConstructorVariant::Record { .. } => self.environment.init_usage( 155 140 used_name.clone(), 156 - EntityKind::ImportedTypeAndValue(location), 141 + EntityKind::ImportedConstructor, 157 142 location, 158 - ); 159 - } else if type_imported { 160 - self.environment 161 - .init_usage(used_name.clone(), EntityKind::ImportedType, location); 162 - let _ = self.environment.ambiguous_imported_items.insert( 163 - import_name.clone(), 164 - LayerUsage { 165 - import_location: location, 166 - type_: true, 167 - value: false, 168 - }, 169 - ); 170 - } else if value_imported { 171 - match variant { 172 - Some(&ValueConstructorVariant::Record { .. }) => self.environment.init_usage( 173 - used_name.clone(), 174 - EntityKind::ImportedConstructor, 175 - location, 176 - ), 177 - _ => self.environment.init_usage( 178 - used_name.clone(), 179 - EntityKind::ImportedValue, 180 - location, 181 - ), 182 - }; 183 - } else if !value_imported { 184 - // Error if no type or value was found with that name 185 - return Err(Error::UnknownModuleValue { 186 - location, 187 - name: import_name.clone(), 188 - module_name: module.name.clone(), 189 - value_constructors: module.public_value_names(), 190 - }); 191 - } 143 + ), 144 + _ => { 145 + self.environment 146 + .init_usage(used_name.clone(), EntityKind::ImportedValue, location) 147 + } 148 + }; 192 149 193 150 // Check if value already was imported 194 151 if let Some(previous) = self.environment.unqualified_imported_names.get(used_name) {
-1
compiler-core/src/build/package_loader/tests.rs
··· 47 47 values: Default::default(), 48 48 accessors: Default::default(), 49 49 unused_imports: Vec::new(), 50 - type_only_unqualified_imports: Vec::new(), 51 50 }; 52 51 let path = Utf8Path::new("/artefact").join(format!("{name}.cache")); 53 52 fs.write_bytes(
+7 -17
compiler-core/src/javascript.rs
··· 363 363 364 364 let module_name = format!("${module_name}"); 365 365 let path = self.import_path(package, module); 366 - let unqualified_imports = unqualified 367 - .iter() 368 - // We do not create a JS import for types as they are not used at runtime 369 - .filter(|import| { 370 - !self 371 - .module 372 - .type_info 373 - .type_only_unqualified_imports 374 - .contains(&import.name) 375 - }) 376 - .map(|i| { 377 - let alias = i.as_name.as_ref().map(|n| { 378 - self.register_in_scope(n); 379 - maybe_escape_identifier_doc(n) 380 - }); 381 - let name = maybe_escape_identifier_doc(&i.name); 382 - Member { name, alias } 366 + let unqualified_imports = unqualified.iter().map(|i| { 367 + let alias = i.as_name.as_ref().map(|n| { 368 + self.register_in_scope(n); 369 + maybe_escape_identifier_doc(n) 383 370 }); 371 + let name = maybe_escape_identifier_doc(&i.name); 372 + Member { name, alias } 373 + }); 384 374 385 375 let aliases = if discarded { vec![] } else { vec![module_name] }; 386 376 imports.register_module(path, aliases, unqualified_imports);
+1 -55
compiler-core/src/javascript/tests/modules.rs
··· 1 1 use crate::javascript::tests::CURRENT_PACKAGE; 2 - use crate::{assert_js, assert_js_with_multiple_imports, assert_ts_def}; 2 + use crate::{assert_js, assert_js_with_multiple_imports}; 3 3 4 4 #[test] 5 5 fn empty_module() { ··· 147 147 (CURRENT_PACKAGE, "one/two/three", r#"pub fn go() { 1 }"#), 148 148 r#"import one/two/three 149 149 pub fn go() { three.go() } 150 - "#, 151 - ); 152 - } 153 - 154 - #[test] 155 - fn imported_external_types_dont_get_rendered() { 156 - assert_js!( 157 - (CURRENT_PACKAGE, "one/two/three", r#"pub type External"#), 158 - r#"import one/two/three.{External} 159 - 160 - pub fn go() { 1 } 161 - "#, 162 - ); 163 - } 164 - 165 - #[test] 166 - fn imported_custom_types_dont_get_rendered() { 167 - assert_js!( 168 - ( 169 - CURRENT_PACKAGE, 170 - "one/two/three", 171 - r#"pub type Custom { One Two }"# 172 - ), 173 - r#"import one/two/three.{Custom, One, Two} 174 - 175 - pub fn go() -> List(Custom) { [One, Two] } 176 - "#, 177 - ); 178 - } 179 - 180 - #[test] 181 - fn imported_custom_types_do_get_rendered_in_typescript() { 182 - assert_ts_def!( 183 - ( 184 - CURRENT_PACKAGE, 185 - "one/two/three", 186 - r#"pub type Custom { One Two }"# 187 - ), 188 - r#"import one/two/three.{Custom, One, Two} 189 - 190 - pub fn go() -> List(Custom) { [One, Two] } 191 - "#, 192 - ); 193 - } 194 - 195 - #[test] 196 - fn imported_external_types_dont_get_rendered_with_value_of_same_name() { 197 - assert_js!( 198 - (CURRENT_PACKAGE, "one/two/three", r#"pub type Thingy"#), 199 - r#"import one/two/three.{Thingy} 200 - 201 - type Dup { Thingy } 202 - 203 - pub fn go(x: Thingy) -> List(Thingy) { [x, x] } 204 150 "#, 205 151 ); 206 152 }
+1 -1
compiler-core/src/language_server/engine.rs
··· 366 366 } 367 367 368 368 // Unqualified types 369 - for unqualified in &import.unqualified_values { 369 + for unqualified in &import.unqualified_types { 370 370 let Some(type_) = module.get_public_type(&unqualified.name) else { 371 371 continue; 372 372 };
+1 -1
compiler-core/src/language_server/tests/completion.rs
··· 665 665 pub type Zoo = List(String) 666 666 type Private = List(String) 667 667 "; 668 - let code = "import dep.{Zoo} 668 + let code = "import dep.{type Zoo} 669 669 670 670 pub fn wibble( 671 671 _: String,
-1
compiler-core/src/metadata/module_decoder.rs
··· 77 77 values: read_hashmap!(reader.get_values()?, self, value_constructor), 78 78 accessors: read_hashmap!(reader.get_accessors()?, self, accessors_map), 79 79 unused_imports: read_vec!(reader.get_unused_imports()?, self, src_span), 80 - type_only_unqualified_imports: Vec::new(), 81 80 }) 82 81 } 83 82
-20
compiler-core/src/metadata/tests.rs
··· 50 50 }, 51 51 )] 52 52 .into(), 53 - type_only_unqualified_imports: Vec::new(), 54 53 } 55 54 } 56 55 ··· 72 71 #[test] 73 72 fn empty_module() { 74 73 let module = ModuleInterface { 75 - type_only_unqualified_imports: Vec::new(), 76 74 package: "some_package".into(), 77 75 origin: Origin::Src, 78 76 name: "one/two".into(), ··· 88 86 #[test] 89 87 fn module_with_private_type() { 90 88 let module = ModuleInterface { 91 - type_only_unqualified_imports: Vec::new(), 92 89 package: "some_package".into(), 93 90 origin: Origin::Src, 94 91 name: "a/b".into(), ··· 115 112 #[test] 116 113 fn module_with_unused_import() { 117 114 let module = ModuleInterface { 118 - type_only_unqualified_imports: Vec::new(), 119 115 package: "some_package".into(), 120 116 origin: Origin::Src, 121 117 name: "a".into(), ··· 134 130 #[test] 135 131 fn module_with_app_type() { 136 132 let module = ModuleInterface { 137 - type_only_unqualified_imports: Vec::new(), 138 133 package: "some_package".into(), 139 134 origin: Origin::Src, 140 135 name: "a/b".into(), ··· 161 156 #[test] 162 157 fn module_with_fn_type() { 163 158 let module = ModuleInterface { 164 - type_only_unqualified_imports: Vec::new(), 165 159 package: "some_package".into(), 166 160 origin: Origin::Src, 167 161 name: "a/b".into(), ··· 188 182 #[test] 189 183 fn module_with_tuple_type() { 190 184 let module = ModuleInterface { 191 - type_only_unqualified_imports: Vec::new(), 192 185 package: "some_package".into(), 193 186 origin: Origin::Src, 194 187 name: "a/b".into(), ··· 221 214 222 215 fn make(t1: Arc<Type>, t2: Arc<Type>) -> ModuleInterface { 223 216 ModuleInterface { 224 - type_only_unqualified_imports: Vec::new(), 225 217 package: "some_package".into(), 226 218 origin: Origin::Src, 227 219 name: "a/b".into(), ··· 254 246 255 247 fn make(type_: Arc<Type>) -> ModuleInterface { 256 248 ModuleInterface { 257 - type_only_unqualified_imports: Vec::new(), 258 249 package: "some_package".into(), 259 250 origin: Origin::Src, 260 251 name: "a".into(), ··· 283 274 #[test] 284 275 fn module_type_to_constructors_mapping() { 285 276 let module = ModuleInterface { 286 - type_only_unqualified_imports: Vec::new(), 287 277 package: "some_package".into(), 288 278 origin: Origin::Src, 289 279 name: "a".into(), ··· 307 297 #[test] 308 298 fn module_fn_value() { 309 299 let module = ModuleInterface { 310 - type_only_unqualified_imports: Vec::new(), 311 300 package: "some_package".into(), 312 301 origin: Origin::Src, 313 302 name: "a".into(), ··· 342 331 #[test] 343 332 fn deprecated_module_fn_value() { 344 333 let module = ModuleInterface { 345 - type_only_unqualified_imports: Vec::new(), 346 334 package: "some_package".into(), 347 335 origin: Origin::Src, 348 336 name: "a".into(), ··· 379 367 #[test] 380 368 fn private_module_fn_value() { 381 369 let module = ModuleInterface { 382 - type_only_unqualified_imports: Vec::new(), 383 370 package: "some_package".into(), 384 371 origin: Origin::Src, 385 372 name: "a".into(), ··· 416 403 #[test] 417 404 fn module_fn_value_regression() { 418 405 let module = ModuleInterface { 419 - type_only_unqualified_imports: Vec::new(), 420 406 package: "some_package".into(), 421 407 origin: Origin::Src, 422 408 name: "a/b/c".into(), ··· 452 438 #[test] 453 439 fn module_fn_value_with_field_map() { 454 440 let module = ModuleInterface { 455 - type_only_unqualified_imports: Vec::new(), 456 441 package: "some_package".into(), 457 442 origin: Origin::Src, 458 443 name: "a".into(), ··· 490 475 let mut random = rand::thread_rng(); 491 476 492 477 let module = ModuleInterface { 493 - type_only_unqualified_imports: Vec::new(), 494 478 package: "some_package".into(), 495 479 origin: Origin::Src, 496 480 name: "a".into(), ··· 530 514 let mut random = rand::thread_rng(); 531 515 532 516 let module = ModuleInterface { 533 - type_only_unqualified_imports: Vec::new(), 534 517 package: "some_package".into(), 535 518 origin: Origin::Src, 536 519 name: "a".into(), ··· 571 554 #[test] 572 555 fn accessors() { 573 556 let module = ModuleInterface { 574 - type_only_unqualified_imports: Vec::new(), 575 557 package: "some_package".into(), 576 558 origin: Origin::Src, 577 559 name: "a".into(), ··· 775 757 }; 776 758 777 759 let module = ModuleInterface { 778 - type_only_unqualified_imports: Vec::new(), 779 760 package: "some_package".into(), 780 761 origin: Origin::Src, 781 762 name: "a".into(), ··· 978 959 #[test] 979 960 fn deprecated_type() { 980 961 let module = ModuleInterface { 981 - type_only_unqualified_imports: Vec::new(), 982 962 package: "some_package".into(), 983 963 origin: Origin::Src, 984 964 name: "a/b".into(),
-2
compiler-core/src/type_.rs
··· 483 483 pub values: HashMap<EcoString, ValueConstructor>, 484 484 pub accessors: HashMap<EcoString, AccessorsMap>, 485 485 pub unused_imports: Vec<SrcSpan>, 486 - pub type_only_unqualified_imports: Vec<EcoString>, 487 486 } 488 487 489 488 #[derive(Debug, Clone, PartialEq, Eq)] ··· 514 513 values: Default::default(), 515 514 accessors: Default::default(), 516 515 unused_imports: Default::default(), 517 - type_only_unqualified_imports: Default::default(), 518 516 } 519 517 } 520 518
+9 -56
compiler-core/src/type_/environment.rs
··· 1 1 use crate::{ 2 - ast::{Layer, PIPE_VARIABLE}, 3 - build::Target, 4 - uid::UniqueIdGenerator, 5 - warning::TypeWarningEmitter, 2 + ast::PIPE_VARIABLE, build::Target, uid::UniqueIdGenerator, warning::TypeWarningEmitter, 6 3 }; 7 4 8 5 use super::*; ··· 52 49 /// stack for an entity with that name and mark it as used. 53 50 /// NOTE: The bool in the tuple here tracks if the entity has been used 54 51 pub entity_usages: Vec<HashMap<EcoString, (EntityKind, SrcSpan, bool)>>, 55 - 56 - pub ambiguous_imported_items: HashMap<EcoString, LayerUsage>, 57 - } 58 - 59 - #[derive(Debug, Clone, Copy, PartialEq, Eq)] 60 - pub struct LayerUsage { 61 - pub import_location: SrcSpan, 62 - pub type_: bool, 63 - pub value: bool, 64 - } 65 - 66 - impl LayerUsage { 67 - fn used(&mut self, layer: Layer) { 68 - match layer { 69 - Layer::Value => self.value = true, 70 - Layer::Type => self.type_ = true, 71 - } 72 - } 73 52 } 74 53 75 54 impl<'a> Environment<'a> { ··· 102 81 current_module, 103 82 warnings, 104 83 entity_usages: vec![HashMap::new()], 105 - ambiguous_imported_items: HashMap::new(), 106 84 } 107 85 } 108 86 } ··· 116 94 PrivateFunction, 117 95 ImportedConstructor, 118 96 ImportedType, 119 - ImportedTypeAndValue(SrcSpan), 120 97 ImportedValue, 121 98 PrivateType, 122 99 Variable, ··· 259 236 /// Lookup a module constant in the current scope. 260 237 /// 261 238 pub fn get_module_const(&mut self, name: &EcoString) -> Option<&ValueConstructor> { 262 - self.increment_usage(name, Layer::Value); 239 + self.increment_usage(name); 263 240 self.module_values 264 241 .get(name) 265 242 .filter(|ValueConstructor { variant, .. }| { ··· 508 485 // TODO: Improve this so that we can tell if an imported overriden 509 486 // type is actually used or not by tracking whether usages apply to 510 487 // the value or type scope 511 - Some((ImportedType | ImportedTypeAndValue(_) | PrivateType, _, _)) => {} 488 + Some((ImportedType | PrivateType, _, _)) => {} 512 489 513 490 Some((kind, location, false)) => { 514 491 // an entity was overwritten in the top most scope without being used ··· 522 499 } 523 500 524 501 /// Increments an entity's usage in the current or nearest enclosing scope 525 - pub fn increment_usage(&mut self, name: &EcoString, layer: Layer) { 502 + pub fn increment_usage(&mut self, name: &EcoString) { 526 503 let mut name = name.clone(); 527 504 528 505 while let Some((kind, _, used)) = self ··· 538 515 EntityKind::PrivateTypeConstructor(type_name) if *type_name != name => { 539 516 name = type_name.clone(); 540 517 } 541 - EntityKind::ImportedTypeAndValue(location) => { 542 - self.ambiguous_imported_items 543 - .entry(name.clone()) 544 - .or_insert_with(|| LayerUsage { 545 - import_location: *location, 546 - type_: false, 547 - value: false, 548 - }) 549 - .used(layer); 550 - break; 551 - } 552 518 _ => break, 553 - } 554 - } 555 - } 556 - 557 - pub fn emit_warnings_for_deprecated_type_imports(&mut self) { 558 - for (name, usage) in &self.ambiguous_imported_items { 559 - if usage.type_ { 560 - self.warnings.emit(Warning::DeprecatedTypeImport { 561 - name: name.clone(), 562 - location: usage.import_location, 563 - }) 564 519 } 565 520 } 566 521 } ··· 598 553 fn handle_unused(&mut self, unused: HashMap<EcoString, (EntityKind, SrcSpan, bool)>) { 599 554 for (name, (kind, location, _)) in unused.into_iter().filter(|(_, (_, _, used))| !used) { 600 555 let warning = match kind { 601 - EntityKind::ImportedType | EntityKind::ImportedTypeAndValue(_) => { 602 - Warning::UnusedType { 603 - name, 604 - imported: true, 605 - location, 606 - } 607 - } 556 + EntityKind::ImportedType => Warning::UnusedType { 557 + name, 558 + imported: true, 559 + location, 560 + }, 608 561 EntityKind::ImportedConstructor => Warning::UnusedConstructor { 609 562 name, 610 563 imported: true,
-5
compiler-core/src/type_/error.rs
··· 404 404 location: SrcSpan, 405 405 }, 406 406 407 - DeprecatedTypeImport { 408 - location: SrcSpan, 409 - name: EcoString, 410 - }, 411 - 412 407 InexhaustiveCaseExpression { 413 408 location: SrcSpan, 414 409 missing: Vec<EcoString>,
+1 -1
compiler-core/src/type_/expression.rs
··· 1696 1696 })?; 1697 1697 1698 1698 // Register the value as seen for detection of unused values 1699 - self.environment.increment_usage(name, Layer::Value); 1699 + self.environment.increment_usage(name); 1700 1700 1701 1701 constructor 1702 1702 }
+1 -1
compiler-core/src/type_/hydrator.rs
··· 143 143 // We do not track use of qualified type constructors as they may be 144 144 // used in another module. 145 145 if module.is_none() { 146 - environment.increment_usage(name, Layer::Type); 146 + environment.increment_usage(name); 147 147 } 148 148 149 149 // Ensure that the correct number of arguments have been given to the constructor
+2 -2
compiler-core/src/type_/pattern.rs
··· 233 233 name: name.clone(), 234 234 variables: self.environment.local_value_names(), 235 235 })?; 236 - self.environment.increment_usage(&name, Layer::Value); 236 + self.environment.increment_usage(&name); 237 237 let typ = 238 238 self.environment 239 239 .instantiate(vc.type_.clone(), &mut hashmap![], self.hydrator); ··· 411 411 .. 412 412 } => { 413 413 // Register the value as seen for detection of unused values 414 - self.environment.increment_usage(&name, Layer::Value); 414 + self.environment.increment_usage(&name); 415 415 416 416 let cons = self 417 417 .environment
-1
compiler-core/src/type_/prelude.rs
··· 181 181 }; 182 182 183 183 let mut prelude = ModuleInterface { 184 - type_only_unqualified_imports: Vec::new(), 185 184 name: PRELUDE_MODULE_NAME.into(), 186 185 package: "".into(), 187 186 origin: Origin::Src,
-1
compiler-core/src/type_/tests.rs
··· 516 516 assert_eq!( 517 517 module.type_info, 518 518 ModuleInterface { 519 - type_only_unqualified_imports: Vec::new(), 520 519 origin: Origin::Src, 521 520 package: "thepackage".into(), 522 521 name: "ok".into(),
+5 -5
compiler-core/src/type_/tests/snapshots/gleam_core__type___tests__imports__unqualified_using_opaque_constructo.snap
··· 3 3 assertion_line: 175 4 4 expression: "import one.{Two}\n\npub fn main() {\n Two\n}" 5 5 --- 6 - error: Unknown variable 7 - ┌─ /src/one/two.gleam:4:3 6 + error: Unknown module field 7 + ┌─ /src/one/two.gleam:1:13 8 8 9 - 4 │ Two 10 - │ ^^^ Did you mean `Nil`? 9 + 1 │ import one.{Two} 10 + │ ^^^ 11 11 12 - The name `Two` is not in scope here. 12 + The module `one` does not have a `Two` value. 13 13
-44
compiler-core/src/type_/tests/warnings.rs
··· 1074 1074 } 1075 1075 1076 1076 #[test] 1077 - fn deprecate_type_import_extenal() { 1078 - assert_warning!( 1079 - ("package", "module", "pub type X"), 1080 - " 1081 - import module.{X} 1082 - pub type Y = X 1083 - " 1084 - ); 1085 - } 1086 - 1087 - #[test] 1088 - fn deprecate_type_import_type_alias() { 1089 - assert_warning!( 1090 - ("package", "module", "pub type X = Int"), 1091 - " 1092 - import module.{X} 1093 - pub type Y = X 1094 - " 1095 - ); 1096 - } 1097 - 1098 - #[test] 1099 - fn deprecate_type_import_type_custom_type() { 1100 - assert_warning!( 1101 - ("package", "module", "pub type X { X }"), 1102 - " 1103 - import module.{X} 1104 - pub type Y = X 1105 - " 1106 - ); 1107 - } 1108 - 1109 - #[test] 1110 - fn deprecate_type_import_type_custom_type_not_using_type() { 1111 - assert_no_warnings!( 1112 - ("package", "module", "pub type X { X }"), 1113 - " 1114 - import module.{X} 1115 - pub const x = X 1116 - " 1117 - ); 1118 - } 1119 - 1120 - #[test] 1121 1077 fn unused_module_wuth_alias_warning_test() { 1122 1078 assert_warning!( 1123 1079 ("gleam/foo", "pub const one = 1"),
-24
compiler-core/src/warning.rs
··· 613 613 } 614 614 } 615 615 616 - type_::Warning::DeprecatedTypeImport { name, location } => { 617 - let text = wrap(&format!( 618 - "The syntax for importing a type has changed. The new syntax is: 619 - 620 - import module.{{type {name}}} 621 - " 622 - )); 623 - Diagnostic { 624 - title: "Deprecated type import".into(), 625 - text, 626 - hint: Some("Run `gleam fix` to auto-fix your code.".into()), 627 - level: diagnostic::Level::Warning, 628 - location: Some(Location { 629 - src: src.clone(), 630 - path: path.to_path_buf(), 631 - label: diagnostic::Label { 632 - text: None, 633 - span: *location, 634 - }, 635 - extra_labels: Vec::new(), 636 - }), 637 - } 638 - } 639 - 640 616 type_::Warning::InexhaustiveLetAssignment { location, missing } => { 641 617 let mut text: String = 642 618 "This assignment uses a pattern that does not match all possible
+1 -1
test-package-compiler/cases/opaque_type_accessor/src/two.gleam
··· 1 - import one.{User} 1 + import one.{type User} 2 2 3 3 // This operation is not permitted because the type is opaque and this module 4 4 // did not define the custom type.
-3
test-package-compiler/cases/opaque_type_construct/gleam.toml
··· 1 - name = "importy" 2 - version = "0.1.0" 3 - target = "erlang"
-21
test-package-compiler/cases/opaque_type_construct/src/one.gleam
··· 1 - pub opaque type User { 2 - User(name: String, score: Int) 3 - } 4 - 5 - // These operations are permitted in this module as it is the one that defined 6 - // the custom type 7 - 8 - pub fn construct() { 9 - User(name: "Alim", score: 10) 10 - } 11 - 12 - pub fn accessors(user: User) { 13 - let name = user.name 14 - let score = user.score 15 - #(name, score) 16 - } 17 - 18 - pub fn destructure(user: User) { 19 - let User(name: name, score: score) = user 20 - #(name, score) 21 - }
-8
test-package-compiler/cases/opaque_type_construct/src/two.gleam
··· 1 - import one.{User} 2 - 3 - // This operation is not permitted because the type is opaque and this module 4 - // did not define the custom type. 5 - 6 - pub fn construct() { 7 - User(name: "Alim", score: 10) 8 - }
+3 -3
test-package-compiler/cases/opaque_type_destructure/src/two.gleam
··· 1 - import one.{User} 1 + import one 2 2 3 3 // This operation is not permitted because the type is opaque and this module 4 4 // did not define the custom type. 5 5 6 - pub fn destructure(user: User) { 7 - let User(name: name, score: score) = user 6 + pub fn destructure(user: one.User) { 7 + let one.User(name: name, score: score) = user 8 8 #(name, score) 9 9 }
-12
test-package-compiler/src/generated_tests.rs
··· 243 243 244 244 #[rustfmt::skip] 245 245 #[test] 246 - fn opaque_type_construct() { 247 - let output = 248 - crate::prepare("./cases/opaque_type_construct"); 249 - insta::assert_snapshot!( 250 - "opaque_type_construct", 251 - output, 252 - "./cases/opaque_type_construct" 253 - ); 254 - } 255 - 256 - #[rustfmt::skip] 257 - #[test] 258 246 fn opaque_type_destructure() { 259 247 let output = 260 248 crate::prepare("./cases/opaque_type_destructure");
+5 -5
test-package-compiler/src/snapshots/test_package_compiler__generated_tests__opaque_type_destructure.snap
··· 1 1 --- 2 2 source: test-package-compiler/src/generated_tests.rs 3 - assertion_line: 261 3 + assertion_line: 249 4 4 expression: "./cases/opaque_type_destructure" 5 5 --- 6 - error: Unknown variable 6 + error: Unknown module field 7 7 ┌─ src/two.gleam:7:7 8 8 9 - 7 │ let User(name: name, score: score) = user 10 - │ ^ Did you mean `user`? 9 + 7 │ let one.User(name: name, score: score) = user 10 + │ ^ Did you mean `accessors`? 11 11 12 - The name `User` is not in scope here. 12 + The module `one` does not have a `User` value. 13 13