Skip to content
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

Fix ambiguous for TwoWire::requestFrom() methods and align API with Arduino.cc #8817

Merged
merged 27 commits into from
Jan 31, 2024

Conversation

safocl
Copy link
Contributor

@safocl safocl commented Oct 30, 2023

Description of Change

Remove (comment out) the TwoWire::requestFrom() method overloads.
The compiler says "warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second"

Tests scenarios

Example 1
Example 2
Example 3
All compilers report this warning.

Related links

C++17 standard says ([over.match.best]):

If there is exactly one viable function that is a better function than all other viable functions, then it is the one selected by overload resolution; otherwise the call is ill-formed.) [ Example:

void Fcn(const int*,  short);
void Fcn(int*, int);

int i;
short s = 0;

void f() {
  Fcn(&i, s);       // is ambiguous because &i → int* is better than &i → const int*
                    // but s → short is also better than s → int

  Fcn(&i, 1L);      // calls Fcn(int*, int), because &i → int* is better than &i → const int*
                    // and 1L → short and 1L → int are indistinguishable

  Fcn(&i, 'c');     // calls Fcn(int*, int), because &i → int* is better than &i → const int*
                    // and c → int is better than c → short
}
 — end example ]

There is no viable override for these methods that is better - any overrides require equal conversions of different arguments.

upd: this pull request now reflects the accumulated changes for all errors and warnings about ambiguous TwoWire method overloads. It was decided to make a HardwareI2C interface from Arduino.

@CLAassistant
Copy link

CLAassistant commented Oct 30, 2023

CLA assistant check
All committers have signed the CLA.

@safocl
Copy link
Contributor Author

safocl commented Oct 30, 2023

This is an error, not a warning: g++ requires the -pedantic option to conform to the standard.

Inside the function, this overload truncated the data type to a shorter one. This could break some users' hopes.
@safocl
Copy link
Contributor Author

safocl commented Oct 30, 2023

I believe that additional method overloads are not the best solution for disambiguating overload resolution. I believe that requests #5764 and #5768 are erroneous. -- That requests are not solve issue arduino-libraries/ArduinoECCX08#25

@VojtechBartoska VojtechBartoska added the Status: Review needed Issue or PR is awaiting review label Nov 1, 2023
@VojtechBartoska
Copy link
Contributor

Thanks for the PR, same here please sign CLA.

@safocl
Copy link
Contributor Author

safocl commented Nov 1, 2023

Thanks for the PR, same here please sign CLA.

Oh yes. I didn’t understand at first that this needed to be done.
I did it.

- implement proposal espressif#8818 (comment)
  to bring the HARDWARE interface into compliance
@VojtechBartoska VojtechBartoska added the Status: Needs investigation We need to do some research before taking next steps on this issue label Nov 28, 2023
@VojtechBartoska VojtechBartoska added this to the 3.0.0 milestone Nov 29, 2023
@lucasssvaz lucasssvaz added the hil_test Run Hardware Tests label Jan 17, 2024
Copy link
Contributor

github-actions bot commented Jan 17, 2024

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "Fix TwoWire::end() return type.":
    • summary should not end with a period (full stop)
    • summary looks empty
    • type/action looks empty
  • the commit message "Fix TwoWire::setClock() return type.":
    • summary should not end with a period (full stop)
    • summary looks empty
    • type/action looks empty
  • the commit message "Fix ambiguous for TwoWire::requestFrom() methods.":
    • summary should not end with a period (full stop)
    • summary looks empty
    • type/action looks empty
  • the commit message "Fix no return statement in the TwoWire::requestFrom.":
    • summary should not end with a period (full stop)
    • summary looks empty
    • type/action looks empty
  • the commit message "Remove TwoWire::begin(int) overload":
    • body's lines must not be longer than 100 characters
    • summary looks empty
    • type/action looks empty
    • body must have leading blank line
  • the commit message "Rewrite TwoWire with using HardwareI2C":
    • footer must have leading blank line
    • summary looks empty
    • type/action looks empty
  • the commit message "fix(libraries/Wire): fix bad return-statement":
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
  • the commit message "fix(libraries/Wire): fix return type":
    • summary looks too short
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
  • the commit message "fix(libraries/Wire): hide slave support elements":
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
    • body must have leading blank line
  • the commit message "fix(libraries/Wire): restore an accidentally deleted implementation":
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
    • body must have leading blank line
  • the commit message "refactor(libraries/Wire): add return statement if slave isn't supported":
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
  • the commit message "refactor(libraries/Wire): fix indentation":
    • summary looks too short
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
  • the commit message "refactor(libraries/Wire): fix indentation":
    • summary looks too short
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
  • the commit message "refactor(libraries/Wire): fix indentation":
    • summary looks too short
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
  • the commit message "refactor(libraries/Wire): remove temporary comment":
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
  • the commit message "refactor(libraries/Wire): remove unnecessary empty lines":
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
  • the commit message "refactor(libraries/Wire): remove unused variables":
    • body's lines must not be longer than 100 characters
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
    • body must have leading blank line
  • the commit message "refactor(libraries/Wire): remove unused variables":
    • body's lines must not be longer than 100 characters
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
    • body must have leading blank line
  • the commit message "refactor(libraries/Wire): return return types":
    • summary looks too short
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
    • body must have leading blank line
  • the commit message "refactor(libraries/Wire): use slave without support":
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
    • body must have leading blank line
  • the commit message "style(libraries/Wire): replace tabs with spaces":
    • scope/component should be lowercase without whitespace, allowed special characters are _ / . , * - .
    • type/action should be one of [change, ci, docs, feat, fix, refactor, remove, revert, test]

Please fix these commit messages - here are some basic tips:

  • follow Conventional Commits style
  • correct format of commit message should be: <type/action>(<scope/component>): <summary>, for example fix(esp32): Fixed startup timeout issue
  • allowed types are: change,ci,docs,feat,fix,refactor,remove,revert,test
  • sufficiently descriptive message summary should be between 20 to 72 characters and start with upper case letter
  • avoid Jira references in commit messages (unavailable/irrelevant for our customers)

TIP: Install pre-commit hooks and run this check when committing (uses the Conventional Precommit Linter).

⚠️ Please consider squashing your 27 commits (simplifying branch history).
⚠️

The source branch "TwoWireInheritFromHardwareI2C" incorrect format:

  • contains uppercase letters. This can cause troubles on case-insensitive file systems (macOS).
    Please rename your branch.

👋 Hello safocl, we appreciate your contribution to this project!


Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 311330e

@lucasssvaz
Copy link
Collaborator

@safocl Please fix the CI errors

Remove non-void values of the return-statements in function returning 'void'.
TwoWire::begin(uint8_t address) should be available without slave
support by SoC?
@safocl
Copy link
Contributor Author

safocl commented Jan 18, 2024

@safocl Please fix the CI errors

I made commits.
Need review for TwoWire::begin(uint8_t address) -- it is should be available without slave
support by SoC?

Compiler reports "Wire.cpp:393:15: error: variable 'err' set but not used [-Werror=unused-but-set-variable]".
Copy link
Collaborator

@lucasssvaz lucasssvaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should remove the error checking from the function return. It is a good way to check if everything inside the method was correctly checked.

The aim of this PR is fixing the ambiguity of the requestFrom methods. I think it is fine to create a HardwareI2C class here but removing the return values should be done in another PR so it can be discussed.

@lucasssvaz lucasssvaz changed the title Fix ambiguous for TwoWire::requestFrom() methods. Fix ambiguous for TwoWire::requestFrom() methods and align API with Arduino.cc Jan 22, 2024
Copy link
Collaborator

@lucasssvaz lucasssvaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussing with the team we agreed that it is better to keep the return types in the abstract class and the implementation even if differ from the Arduino.cc API.

@safocl
Copy link
Contributor Author

safocl commented Jan 23, 2024

After discussing with the team we agreed that it is better to keep the return types in the abstract class and the implementation even if differ from the Arduino.cc API.

Do I need to return the return types as they were originally and change them in the abstract class itself?

@me-no-dev
Copy link
Member

Yes. change HardwareI2C and revert in Wire

@lucasssvaz lucasssvaz added Resolution: Awaiting response Waiting for response of author and removed Status: Needs investigation We need to do some research before taking next steps on this issue labels Jan 26, 2024
Copy link
Member

@P-R-O-C-H-Y P-R-O-C-H-Y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@safocl PTAL

libraries/Wire/src/Wire.h Outdated Show resolved Hide resolved
Copy link
Member

@P-R-O-C-H-Y P-R-O-C-H-Y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just small formatting fixes, else looks good.
Tested i2c with OLED, works fine.

libraries/Wire/src/Wire.cpp Outdated Show resolved Hide resolved
libraries/Wire/src/Wire.cpp Outdated Show resolved Hide resolved
libraries/Wire/src/Wire.cpp Outdated Show resolved Hide resolved
libraries/Wire/src/Wire.h Outdated Show resolved Hide resolved
Copy link
Member

@P-R-O-C-H-Y P-R-O-C-H-Y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @safocl, great job!

@P-R-O-C-H-Y P-R-O-C-H-Y added Status: Pending Merge Pull Request is ready to be merged and removed Resolution: Awaiting response Waiting for response of author Status: Review needed Issue or PR is awaiting review labels Jan 29, 2024
@VojtechBartoska VojtechBartoska modified the milestones: 3.0.0, 3.0.0-RC1 Jan 30, 2024
@me-no-dev me-no-dev merged commit 7966f4a into espressif:master Jan 31, 2024
136 of 139 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hil_test Run Hardware Tests Status: Pending Merge Pull Request is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants