-
-
Notifications
You must be signed in to change notification settings - Fork 853
Closed
Description
Configuration
Operating system: Windows 10
PlatformIO Version (platformio --version): 3.6.0a2
Description of problem
When building an .ino file with functions returning reference types, the file is not correctly preprocessed. If the functions are not declared in the order in which they are called, the build fails with "function was not declared in this scope". The same code compiles without error in the Arduino IDE.
Other types of functions are not affected by this and can be declared in any order without breaking anything.
Steps to Reproduce
- Create a function that returns a reference type (see below for an example)
- Create a function that calls the function that returns the reference type. Ensure this second function is declared before the function that it calls
- Build project - failure will result with "function not declared in this scope" error
- Swap order of functions so declaration occurs before call
- Build project - will build successfully.
Actual Results
bug_report.ino: In function 'void normalFunction()':
bug_report.ino:5:35: error: 'jsonFunction' was not declared in this scope
JsonObject& json = jsonFunction();
Expected Results
Project should build successfully.
If problems with PlatformIO Build System:
The content of platformio.ini:
[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
[platformio]
src_dir = bug_report
lib_dir = ~\Documents\Arduino\librariesSource file to reproduce issue:
#include "Arduino.h"
#include "ArduinoJson.h"
void normalFunction() {
JsonObject& json = jsonFunction();
}
JsonObject& jsonFunction() {
return JsonObject::invalid();
}
void setup() {}
void loop() {}Additional info
Playing around, with this a bit more, I've discovered that this also affects functions returning a float.
Reactions are currently unavailable