···643643 } => self.track_feature_usage(FeatureKind::InternalAnnotation, location),
644644 }
645645646646- if let Some((module, _, location)) = &external_javascript {
647647- if module.contains('@') {
648648- self.track_feature_usage(FeatureKind::AtInJavascriptModules, *location)
649649- }
646646+ if let Some((module, _, location)) = &external_javascript
647647+ && module.contains('@')
648648+ {
649649+ self.track_feature_usage(FeatureKind::AtInJavascriptModules, *location)
650650 }
651651652652 // Assert that the inferred type matches the type of any recursive call
···1558155815591559 // Then if the required version is not in the specified version for the
15601560 // range we emit a warning highlighting the usage of the feature.
15611561- if let Some(gleam_version) = &self.package_config.gleam_version {
15621562- if let Some(lowest_allowed_version) = gleam_version.lowest_version() {
15631563- // There is a version in the specified range that is lower than
15641564- // the one required by this feature! This means that the
15651565- // specified range is wrong and would allow someone to run a
15661566- // compiler that is too old to know of this feature.
15671567- if minimum_required_version > lowest_allowed_version {
15681568- self.problems
15691569- .warning(Warning::FeatureRequiresHigherGleamVersion {
15701570- location,
15711571- feature_kind,
15721572- minimum_required_version: minimum_required_version.clone(),
15731573- wrongfully_allowed_version: lowest_allowed_version,
15741574- })
15751575- }
15611561+ if let Some(gleam_version) = &self.package_config.gleam_version
15621562+ && let Some(lowest_allowed_version) = gleam_version.lowest_version()
15631563+ {
15641564+ // There is a version in the specified range that is lower than
15651565+ // the one required by this feature! This means that the
15661566+ // specified range is wrong and would allow someone to run a
15671567+ // compiler that is too old to know of this feature.
15681568+ if minimum_required_version > lowest_allowed_version {
15691569+ self.problems
15701570+ .warning(Warning::FeatureRequiresHigherGleamVersion {
15711571+ location,
15721572+ feature_kind,
15731573+ minimum_required_version: minimum_required_version.clone(),
15741574+ wrongfully_allowed_version: lowest_allowed_version,
15751575+ })
15761576 }
15771577 }
15781578
···21982198 let item_location = item.location();
21992199 // A list has multiple items on the same line if two consecutive
22002200 // ones do not span multiple lines.
22012201- if let Some(previous) = previous {
22022202- if !self.spans_multiple_lines(previous.end, item_location.start) {
22032203- return true;
22042204- }
22012201+ if let Some(previous) = previous
22022202+ && !self.spans_multiple_lines(previous.end, item_location.start)
22032203+ {
22042204+ return true;
22052205 }
22062206 previous = Some(item_location);
22072207 }
···17541754 // If there's no arguments and the type is a function that takes
17551755 // arguments then this is the constructor being referenced, not the
17561756 // function being called.
17571757- if let Some(arity) = type_.fn_arity() {
17581758- if arguments.is_empty() && arity != 0 {
17591759- let arity = arity as u16;
17601760- return record_constructor(type_.clone(), None, name, arity, self.tracker);
17611761- }
17571757+ if let Some(arity) = type_.fn_arity()
17581758+ && arguments.is_empty()
17591759+ && arity != 0
17601760+ {
17611761+ let arity = arity as u16;
17621762+ return record_constructor(type_.clone(), None, name, arity, self.tracker);
17621763 }
1763176417641765 let field_values = arguments
···21352136 // If there's no arguments and the type is a function that takes
21362137 // arguments then this is the constructor being referenced, not the
21372138 // function being called.
21382138- if let Some(arity) = type_.fn_arity() {
21392139- if arguments.is_empty() && arity != 0 {
21402140- let arity = arity as u16;
21412141- return record_constructor(type_.clone(), None, name, arity, self.tracker);
21422142- }
21392139+ if let Some(arity) = type_.fn_arity()
21402140+ && arguments.is_empty()
21412141+ && arity != 0
21422142+ {
21432143+ let arity = arity as u16;
21442144+ return record_constructor(type_.clone(), None, name, arity, self.tracker);
21432145 }
2144214621452147 let field_values = arguments
···455455 if let Some(module) = import.used_name() {
456456 // If the user has already started a module select then don't show irrelevant modules.
457457 // e.x. when the user has typed mymodule.| we should only show items from mymodule.
458458- if let Some(input_mod_name) = &module_select {
459459- if &module != input_mod_name {
460460- continue;
461461- }
458458+ if let Some(input_mod_name) = &module_select
459459+ && &module != input_mod_name
460460+ {
461461+ continue;
462462 }
463463 completions.push(type_completion(
464464 Some(&module),
···515515516516 // If the user has already started a module select then don't show irrelevant modules.
517517 // e.x. when the user has typed mymodule.| we should only show items from mymodule.
518518- if let Some(input_mod_name) = &module_select {
519519- if qualifier != input_mod_name {
520520- continue;
521521- }
518518+ if let Some(input_mod_name) = &module_select
519519+ && qualifier != input_mod_name
520520+ {
521521+ continue;
522522 }
523523524524 // Qualified types
···650650 if let Some(module) = import.used_name() {
651651 // If the user has already started a module select then don't show irrelevant modules.
652652 // e.x. when the user has typed mymodule.| we should only show items from mymodule.
653653- if let Some(input_mod_name) = &module_select {
654654- if &module != input_mod_name {
655655- continue;
656656- }
653653+ if let Some(input_mod_name) = &module_select
654654+ && &module != input_mod_name
655655+ {
656656+ continue;
657657 }
658658 completions.push(value_completion(
659659 Some(&module),
···709709710710 // If the user has already started a module select then don't show irrelevant modules.
711711 // e.x. when the user has typed mymodule.| we should only show items from mymodule.
712712- if let Some(input_mod_name) = &module_select {
713713- if qualifier != input_mod_name {
714714- continue;
715715- }
712712+ if let Some(input_mod_name) = &module_select
713713+ && qualifier != input_mod_name
714714+ {
715715+ continue;
716716 }
717717718718 // Qualified values
···903903 .error(convert_unify_error(error, value.location()));
904904 }
905905906906- if let TypedExpr::Int { value: ref v, .. } = value {
907907- if v.starts_with('-') {
908908- self.problems
909909- .warning(Warning::UnnecessaryDoubleIntNegation { location });
910910- }
906906+ if let TypedExpr::Int { value: ref v, .. } = value
907907+ && v.starts_with('-')
908908+ {
909909+ self.problems
910910+ .warning(Warning::UnnecessaryDoubleIntNegation { location });
911911 }
912912913913 if let TypedExpr::NegateInt { .. } = value {
···12591259 (Ok(record_access), _) => {
12601260 // If this is actually record access and not module access, and we didn't register
12611261 // the reference earlier, we register it now.
12621262- if let TypedExpr::RecordAccess { record, .. } = &record_access {
12631263- if let TypedExpr::Var {
12621262+ if let TypedExpr::RecordAccess { record, .. } = &record_access
12631263+ && let TypedExpr::Var {
12641264 location,
12651265 constructor,
12661266 name,
12671267 } = record.as_ref()
12681268- {
12691269- self.register_value_constructor_reference(
12701270- name,
12711271- &constructor.variant,
12721272- *location,
12731273- ReferenceKind::Unqualified,
12741274- )
12751275- }
12681268+ {
12691269+ self.register_value_constructor_reference(
12701270+ name,
12711271+ &constructor.variant,
12721272+ *location,
12731273+ ReferenceKind::Unqualified,
12741274+ )
12761275 }
12771276 record_access
12781277 }
···41354134 // argument that is implicitly passed by the compiler.
41364135 // This way we can provide better argument hints for incomplete use
41374136 // expressions.
41384138- if let CallKind::Use { .. } = kind {
41394139- if let Some(last) = arguments.pop() {
41404140- for _ in 0..missing_arguments {
41414141- arguments.push(CallArg {
41424142- label: None,
41434143- location,
41444144- value: UntypedExpr::Placeholder {
41454145- // We intentionally give this an empty span since it
41464146- // is an implicit argument being passed by the compiler
41474147- // that doesn't appear in the source code.
41484148- location: SrcSpan {
41494149- start: last.location().start,
41504150- end: last.location().start,
41514151- },
41374137+ if let CallKind::Use { .. } = kind
41384138+ && let Some(last) = arguments.pop()
41394139+ {
41404140+ for _ in 0..missing_arguments {
41414141+ arguments.push(CallArg {
41424142+ label: None,
41434143+ location,
41444144+ value: UntypedExpr::Placeholder {
41454145+ // We intentionally give this an empty span since it
41464146+ // is an implicit argument being passed by the compiler
41474147+ // that doesn't appear in the source code.
41484148+ location: SrcSpan {
41494149+ start: last.location().start,
41504150+ end: last.location().start,
41524151 },
41534153- implicit: Some(ImplicitCallArgOrigin::IncorrectArityUse),
41544154- });
41554155- }
41564156- arguments.push(last);
41524152+ },
41534153+ implicit: Some(ImplicitCallArgOrigin::IncorrectArityUse),
41544154+ });
41574155 }
41564156+ arguments.push(last);
41584157 };
4159415841604159 // Ensure that the given args have the correct types
···43834382 let mut body = body_typer.infer_statements(body);
4384438343854384 // Check that any return type is accurate.
43864386- if let Some(return_type) = return_type {
43874387- if let Err(error) = unify(return_type, body.last().type_()) {
43884388- let error = error
43894389- .return_annotation_mismatch()
43904390- .into_error(body.last().type_defining_location());
43914391- body_typer.problems.error(error);
43854385+ if let Some(return_type) = return_type
43864386+ && let Err(error) = unify(return_type, body.last().type_())
43874387+ {
43884388+ let error = error
43894389+ .return_annotation_mismatch()
43904390+ .into_error(body.last().type_defining_location());
43914391+ body_typer.problems.error(error);
4392439243934393- // If the return type doesn't match with the annotation we
43944394- // add a new expression to the end of the function to match
43954395- // the annotated type and allow type inference to keep
43964396- // going.
43974397- body.push(Statement::Expression(TypedExpr::Invalid {
43984398- // This is deliberately an empty span since this
43994399- // placeholder expression is implicitly inserted by the
44004400- // compiler and doesn't actually appear in the source
44014401- // code.
44024402- location: SrcSpan {
44034403- start: body.last().location().end,
44044404- end: body.last().location().end,
44054405- },
44064406- type_: body_typer.new_unbound_var(),
44074407- }))
44084408- };
44094409- }
43934393+ // If the return type doesn't match with the annotation we
43944394+ // add a new expression to the end of the function to match
43954395+ // the annotated type and allow type inference to keep
43964396+ // going.
43974397+ body.push(Statement::Expression(TypedExpr::Invalid {
43984398+ // This is deliberately an empty span since this
43994399+ // placeholder expression is implicitly inserted by the
44004400+ // compiler and doesn't actually appear in the source
44014401+ // code.
44024402+ location: SrcSpan {
44034403+ start: body.last().location().end,
44044404+ end: body.last().location().end,
44054405+ },
44064406+ type_: body_typer.new_unbound_var(),
44074407+ }))
44084408+ };
4410440944114410 Ok((arguments, body))
44124411 })
···4499449845004499 // Then if the required version is not in the specified version for the
45014500 // range we emit a warning highlighting the usage of the feature.
45024502- if let Some(gleam_version) = &self.environment.gleam_version {
45034503- if let Some(lowest_allowed_version) = gleam_version.lowest_version() {
45044504- // There is a version in the specified range that is lower than
45054505- // the one required by this feature! This means that the
45064506- // specified range is wrong and would allow someone to run a
45074507- // compiler that is too old to know of this feature.
45084508- if minimum_required_version > lowest_allowed_version {
45094509- self.problems
45104510- .warning(Warning::FeatureRequiresHigherGleamVersion {
45114511- location,
45124512- feature_kind,
45134513- minimum_required_version: minimum_required_version.clone(),
45144514- wrongfully_allowed_version: lowest_allowed_version,
45154515- })
45164516- }
45014501+ if let Some(gleam_version) = &self.environment.gleam_version
45024502+ && let Some(lowest_allowed_version) = gleam_version.lowest_version()
45034503+ {
45044504+ // There is a version in the specified range that is lower than
45054505+ // the one required by this feature! This means that the
45064506+ // specified range is wrong and would allow someone to run a
45074507+ // compiler that is too old to know of this feature.
45084508+ if minimum_required_version > lowest_allowed_version {
45094509+ self.problems
45104510+ .warning(Warning::FeatureRequiresHigherGleamVersion {
45114511+ location,
45124512+ feature_kind,
45134513+ minimum_required_version: minimum_required_version.clone(),
45144514+ wrongfully_allowed_version: lowest_allowed_version,
45154515+ })
45174516 }
45184517 }
45194518
···10011001 }
10021002 }
1003100310041004- if let Some(spread_location) = spread {
10051005- if let ValueConstructorVariant::Record { arity, .. } =
10041004+ if let Some(spread_location) = spread
10051005+ && let ValueConstructorVariant::Record { arity, .. } =
10061006 &constructor.variant
10071007- {
10081008- while pattern_arguments.len() < usize::from(*arity) {
10091009- pattern_arguments.push(CallArg {
10101010- value: Pattern::Discard {
10111011- name: "_".into(),
10121012- location: spread_location,
10131013- type_: (),
10141014- },
10071007+ {
10081008+ while pattern_arguments.len() < usize::from(*arity) {
10091009+ pattern_arguments.push(CallArg {
10101010+ value: Pattern::Discard {
10111011+ name: "_".into(),
10151012 location: spread_location,
10161016- label: None,
10171017- implicit: Some(ImplicitCallArgOrigin::PatternFieldSpread),
10181018- });
10191019- }
10201020- };
10211021- }
10131013+ type_: (),
10141014+ },
10151015+ location: spread_location,
10161016+ label: None,
10171017+ implicit: Some(ImplicitCallArgOrigin::PatternFieldSpread),
10181018+ });
10191019+ }
10201020+ };
10221021 }
10231022 }
10241023···1316131513171316 // Then if the required version is not in the specified version for the
13181317 // range we emit a warning highlighting the usage of the feature.
13191319- if let Some(gleam_version) = &self.environment.gleam_version {
13201320- if let Some(lowest_allowed_version) = gleam_version.lowest_version() {
13211321- // There is a version in the specified range that is lower than
13221322- // the one required by this feature! This means that the
13231323- // specified range is wrong and would allow someone to run a
13241324- // compiler that is too old to know of this feature.
13251325- if minimum_required_version > lowest_allowed_version {
13261326- self.problems
13271327- .warning(Warning::FeatureRequiresHigherGleamVersion {
13281328- location,
13291329- feature_kind,
13301330- minimum_required_version: minimum_required_version.clone(),
13311331- wrongfully_allowed_version: lowest_allowed_version,
13321332- })
13331333- }
13181318+ if let Some(gleam_version) = &self.environment.gleam_version
13191319+ && let Some(lowest_allowed_version) = gleam_version.lowest_version()
13201320+ {
13211321+ // There is a version in the specified range that is lower than
13221322+ // the one required by this feature! This means that the
13231323+ // specified range is wrong and would allow someone to run a
13241324+ // compiler that is too old to know of this feature.
13251325+ if minimum_required_version > lowest_allowed_version {
13261326+ self.problems
13271327+ .warning(Warning::FeatureRequiresHigherGleamVersion {
13281328+ location,
13291329+ feature_kind,
13301330+ minimum_required_version: minimum_required_version.clone(),
13311331+ wrongfully_allowed_version: lowest_allowed_version,
13321332+ })
13341333 }
13351334 }
13361335
···417417 }
418418419419 fn warn_if_call_first_argument_is_hole(&mut self, call: &UntypedExpr) {
420420- if let UntypedExpr::Fn { kind, body, .. } = &call {
421421- if kind.is_capture() {
422422- if let Statement::Expression(UntypedExpr::Call { arguments, .. }) = body.first() {
423423- match arguments.as_slice() {
424424- // If the first argument is labelled, we don't warn the user
425425- // as they might be intentionally adding it to provide more
426426- // information about exactly which argument is being piped into.
427427- [first] | [first, ..]
428428- if first.is_capture_hole() && first.label.is_none() =>
429429- {
430430- self.expr_typer.problems.warning(
431431- Warning::RedundantPipeFunctionCapture {
432432- location: first.location,
433433- },
434434- )
435435- }
436436- _ => (),
437437- }
438438- }
420420+ if let UntypedExpr::Fn { kind, body, .. } = &call
421421+ && kind.is_capture()
422422+ && let Statement::Expression(UntypedExpr::Call { arguments, .. }) = body.first()
423423+ {
424424+ match arguments.as_slice() {
425425+ // If the first argument is labelled, we don't warn the user
426426+ // as they might be intentionally adding it to provide more
427427+ // information about exactly which argument is being piped into.
428428+ [first] | [first, ..] if first.is_capture_hole() && first.label.is_none() => self
429429+ .expr_typer
430430+ .problems
431431+ .warning(Warning::RedundantPipeFunctionCapture {
432432+ location: first.location,
433433+ }),
434434+ _ => (),
439435 }
440436 }
441437 }