Skip to content

Map.cast does not check for narrower key type on lookup #46336

@davidmorgan

Description

@davidmorgan

It's not clear to me from the docs what the intended behaviour is

https://api.dart.dev/stable/2.10.4/dart-core/Map/cast.html

but I found it surprising that

{'one': 1}.cast<int, int>()['one']

succeeds in looking up a String key in a Map<int, int>; I was expecting it to either throw or return nothing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-coretype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions