New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error compiling .ino files with functions returning certain types #1683

Closed
cjastone opened this Issue Jun 14, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@cjastone

cjastone commented Jun 14, 2018

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

  1. Create a function that returns a reference type (see below for an example)
  2. Create a function that calls the function that returns the reference type. Ensure this second function is declared before the function that it calls
  3. Build project - failure will result with "function not declared in this scope" error
  4. Swap order of functions so declaration occurs before call
  5. 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\libraries

Source 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.

@cjastone cjastone changed the title from Error compiling .ino files with functions returning reference types to Error compiling .ino files with functions returning certain types Jun 14, 2018

@ivankravets ivankravets added this to the 3.5.4 milestone Jun 15, 2018

@ivankravets ivankravets added the bug label Jun 15, 2018

ivankravets added a commit that referenced this issue Jun 15, 2018

Merge branch 'hotfix/v3.5.4' into develop
* hotfix/v3.5.4:
  Fix preprocessor for Arduino sketch when function returns certain type // Resolve #1683
@ivankravets

This comment has been minimized.

Member

ivankravets commented Jun 15, 2018

Please re-test with pio upgrade --dev. Thanks!

@cjastone

This comment has been minimized.

cjastone commented Jun 17, 2018

Brilliant - thanks @ivankravets! Compiles without error now.

I really appreciate the fast response on this; keep up the amazing work!

ivankravets added a commit that referenced this issue Jul 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment