Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same warning printed twice #3899

Open
okkdev opened this issue Nov 26, 2024 · 7 comments
Open

Same warning printed twice #3899

okkdev opened this issue Nov 26, 2024 · 7 comments
Labels
bug Something isn't working help wanted Contributions encouraged priority:medium

Comments

@okkdev
Copy link

okkdev commented Nov 26, 2024

My list.concat deprecation warning is being printed twice for the same line/occurrence.

warning: Deprecated value used
    ┌─ /Users/js/Desktop/scream/src/scream.gleam:101:12
    │
101 │     |> list.concat
    │            ^^^^^^^ This value has been deprecated

It was deprecated with this message: Use `list.flatten` instead.

warning: Deprecated value used
    ┌─ /Users/js/Desktop/scream/src/scream.gleam:101:12
    │
101 │     |> list.concat
    │            ^^^^^^^ This value has been deprecated

It was deprecated with this message: Use `list.flatten` instead.

Reproduction

git clone [email protected]:okkdev/scream.git
cd scream/
git checkout dfde544ea477f2e2c27732596c1ab1397612cf41
gleam build

Versions

  • Gleam 1.6.1
  • macOS 14.6.1
  • javascript and erlang target

Log

log.txt

@okkdev okkdev added the bug Something isn't working label Nov 26, 2024
@lpil
Copy link
Member

lpil commented Nov 27, 2024

Oh dear! Thank you

@lpil lpil added help wanted Contributions encouraged priority:medium labels Nov 27, 2024
@GearsDatapacks
Copy link
Member

Looking into this more, it's very strange.

This code prints the warning twice:

import gleam/list

pub fn main() {
  use <- fn(f) { f() }

  list.concat([])
}

However, this doesn't:

import gleam/list

fn usable(f) { f() }

pub fn main() {
  use <- usable

  list.concat([])
}

It only seems to occur if the deprecated value is used inside a use callback, where the right-hand side of the use expression itself is a function literal.

It also prints more times if in several nested use callbacks, doubling each time:

import gleam/list

pub fn main() {
  use <- fn(f) { f() }
  use <- fn(f) { f() }
  use <- fn(f) { f() }

  list.concat([])
  //   ^ This deprecation warning prints 16 times!
}

It does not seem to matter which deprecated value is used.

@lpil
Copy link
Member

lpil commented Nov 28, 2024

^ This deprecation warning prints 16 times!

Oops, ahahaha

I presume we're checking for deprecations in the body once before and once after use is expanded?

@GearsDatapacks
Copy link
Member

Yes that's what I thought too. Could be related to the recent changes to the ast representation of use, when the desugar code action was introduced. Or this could have always been the case, just never noticed before. I'll test on 1.6.2 and then bisect it later.

@GearsDatapacks
Copy link
Member

Ok, so it looks like it was first introduced in 1.5 in d022ff0. My guess is that infer_fn_with_call_context does a second pass over the code and produces duplicate warnings. I'll try and fix this when I get time

@lpil
Copy link
Member

lpil commented Nov 28, 2024

d022ff0#diff-892d21f7b2f39e0c5d4ef6a85f69d96b223f6cd4309106ac900cf9c391abb183R2911

Looks like it's doing some wasteful cloning there too? It clones the call arg but discards the original?

@GearsDatapacks
Copy link
Member

Ok, so looking into this issue more, it's a bit tricky to figure out a way to get this to work. Basically:

  • To infer the arguments, we first infer the left side of the call
  • To be able to determine the types of unannotated arguments in an anonymous function, we first infer the arguments

I'll have a play around with it a bit more to try and figure out a solution without breaking any existing behaviour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Contributions encouraged priority:medium
Projects
None yet
Development

No branches or pull requests

3 participants