Skip to content

Add links to explain behavior on 'Fixing type promotion failures' page #3744

@jamesderlin

Description

@jamesderlin

Page URL

https://dart.dev/tools/non-promotion-reasons.html

Page source

https://github.com/dart-lang/site-www/tree/master/src/tools/non-promotion-reasons.md

Describe the problem

A lot of people are confused that non-local variables aren't automatically promoted by is or null checks. Although https://dart.dev/tools/non-promotion-reasons.html helps explain that the behavior is expected, it doesn't help readers understand the rationale for the behavior, so the inability to promote non-local variables seems arbitrary.

Expected fix

It would be useful to add a note that explains why only local variables can be promoted. Perhaps add links to dart-lang/sdk#21530, dart-lang/sdk#44327, or to https://stackoverflow.com/q/65035574/.

Additional context

No response

Metadata

Metadata

Assignees

Labels

a.languageRelates to the Dart language tourd.enhancementImproves docs with specific askdev.null-safetyRelates to transforming or migrating Dart code to sound null safetydev.type-promotionRelates to type promotion concepts and examplese0-minutesCan complete in < 60 minutes of normal, not dedicated, workfix.linkAdds, changes, or removes a link to a pagefrom.page-issueReported in a reader-filed concernp3-lowValid but not urgent concern. Resolve when possible. Encourage upvote to surface.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions