EEPROM library has weird behaviour. Why?

this compiles:

#include <EEPROM.h>
int addr=10,val=0;
void setup() {
  /** Empty setup. **/
  EEPROM.get(addr,val);
}

void loop() {}

this does not:

#include <EEPROM.h>
int addr=10,val=0;
EEPROM.get(addr,val);
void setup() {
  /** Empty setup. **/
  
}
void loop() {}

get this compiler error:
sketch_mar26b:4: error: 'EEPROM' does not name a type
EEPROM.get(addr,val);
^
exit status 1
'EEPROM' does not name a type

in the second snippet, compiler behaves like EEPROM was not declared anywhere. The question is, why does it find definition when reference is placed in a function. any function. i checked. Drove me nuts for hours.

 EEPROM.get(addr,val);

This needs to be inside a function.
.