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

Named unapply selectors accept random names #22192

Open
KacperFKorban opened this issue Dec 11, 2024 · 6 comments · May be fixed by #22315
Open

Named unapply selectors accept random names #22192

KacperFKorban opened this issue Dec 11, 2024 · 6 comments · May be fixed by #22315
Assignees
Labels
area:named-tuples Issues tied to the named tuples feature. itype:bug

Comments

@KacperFKorban
Copy link
Member

Compiler version

91063dd

Minimized code

//> using scala 3.nightly

import scala.language.experimental.namedTuples

case class City(name: String, population: Int)

def getCityInfo(city: City) =
  city match
    case City(iam = n, confused = p) => s"[City] $n has a population of $p !!!!!!!!!!"

@main
def main =
  val city = City(name = "New York", population = 8_000_000)
  println(getCityInfo(city))

Output

[City] New York has a population of 8000000 !!!!!!!!!!

Expectation

Compilation error, that iam and confused aren't fields of the class City

@KacperFKorban KacperFKorban added itype:bug area:named-tuples Issues tied to the named tuples feature. labels Dec 11, 2024
@KacperFKorban
Copy link
Member Author

The problem is most likely that the tryEither here swallows the error.

@rochala
Copy link
Contributor

rochala commented Dec 19, 2024

I fixed this also by accident, not sure if this is correct approach.

I didn't see this issue.
#22242

@Gedochao Gedochao linked a pull request Dec 19, 2024 that will close this issue
@KacperFKorban
Copy link
Member Author

@rochala I don't think that it's the same issue. This one is related to the compiler not checking the names of the fields, not the combinations of named/unnamed patterns.
Your second explanation point says something that seems similar to this issue, but you don't change anything there.

@rochala
Copy link
Contributor

rochala commented Dec 19, 2024

Right, your error is still suppresed by tryEither...

https://github.com/lampepfl/dotty/blob/91063dd9939ba26f30a538889162b6832cfc2c19/compiler/src/dotty/tools/dotc/ast/Desugar.scala#L1748

checkWellFormedTupleElems does not verify match of names.

@rochala
Copy link
Contributor

rochala commented Dec 19, 2024

My fix then is not complete, as it will also not report anything from that line, while it should.

@KacperFKorban
Copy link
Member Author

We can just treat them as two separate error (which they sort of are).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:named-tuples Issues tied to the named tuples feature. itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants