Automatic type promotion??

I was surprised not to see at least a warning on the small test program below. I have written a function called MySquare() that squares an integer number:

int MySquare(int n)
{
  if (n < 182)      // 182 overflows a 16-bit int
    return n * n;
  else 
    return -1;
}

void setup() {
  int num   = 181;
  float val = 181.0;
  
  Serial.begin(9600);

  num = MySquare(num);
  Serial.println(num);

//  val = MySquare(val);
//  Serial.println(val);
}

void loop() {
}

The code works as expected on the int function argument, but also works correctly on the (currently comment-out) float data, too. The print statement shows the default two decimal places on the float version. I would have expected some kind of type-checking error, but get none. I'm using 1.8.10 on an Arduino Mega2560, Win 10.

The compiler just cast it to int. The two decimal places are the default for printing a float.

You might see a warning if you crank up the level in preferences.

That's what I suspected, which is why I mentioned "The print statement shows the default two decimal places on the float version." Following your lead, I cranked up my Compiler Errors level to All in the Preferences section and all I see is an "unused variable" warning for num or val, depending upon which one is commented out.

I'm not a fan of "silent casts" like the one being demonstrated here, as they sometimes come back to bite you in the butt producing downstream errors that are more difficult to isolate than they should be.