-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 Tuple element selectable even when multiple elements have same name #21301
Comments
The error should be in preventing such named tuple as defined by |
The problem identified is manually constructing the type - it's on you to enforce the uniqueness - if you use the named tuple syntax, or any of the named tuple methods then there is a check It's a bit like asInstanceOf |
@bishabosha I think the questions should rather be:
I think the answer to 2) is clearly "yes". I don't have sufficiently technical knowledge to answer 1), but my assumption was that at |
There could probably be put in an ambiguity check on selection, here is the code taken from def tryNamedTupleSelection() =
val namedTupleElems = qual.tpe.widenDealias.namedTupleElementTypes
val nameIdx = namedTupleElems.indexWhere(_._1 == selName)
if nameIdx >= 0 && Feature.enabled(Feature.namedTuples) then // ? include extra `count == 1` check?
typed(
untpd.Apply(
untpd.Select(untpd.TypedSplice(qual), nme.apply),
untpd.Literal(Constant(nameIdx))),
pt)
else EmptyTree otherwise the cost of peephole checking all types in case they might be some malformed named tuple might be too much |
Potentially relevant to #22192 |
Compiler version
3.5.0-RC5 and others.
Minimized code
Expectation
Compilation error on
y.a
.The text was updated successfully, but these errors were encountered: