Uh, what a sad bug Iiro! You are being bit by implicit downcasts here: clamp uses num so you can pass an int (which is a num) and a double (which is a num) to it as expected.

It also returns a num but textScaleFactor takes a double so why that that not cause a static failure? Because Dart currently by-default [1] allows implicit downcasts. This made some sense in the past when we had a looser type system, but now with null safety we're removing it, so as you can see here you'll get a nice static error: https://nullsafety.dartpad.dev/0e4144019297367c45b63dd1a1fba80c.

Cheers, Michael (Dart product manager)

[1]: you can also remove those now via configuration: https://dart.dev/guides/language/analysis-options#enabling-additional-type-checks

Replying to Michael Thomsen on "iiro.dev"

Go ahead and write your reply below!

GitHub-flavored Markdown & a sane subset of HTML is supported.