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

[epilogue] Generation order of operations incorrect for VarHandle cast with appended Supplier getAs* method #7427

Open
shueja opened this issue Nov 23, 2024 · 0 comments
Labels
type: bug Something isn't working.

Comments

@shueja
Copy link
Contributor

shueja commented Nov 23, 2024

Describe the bug
Epilogue misgenerates code for fields of type BooleanSupplier, IntSupplier, LongSupplier, DoubleSupplier when accessed through a VarHandle.

To Reproduce
Steps to reproduce the behavior:

  1. Try to compile.
  2. ...
Compilation failed; see the compiler output below.
  C:\Users\jashu\git\Epilogue_Supplier_Bug\build\generated\sources\annotationProcessor\java\main\frc\robot\RobotLogger.java:29: error: no suitable method found for log(String,DoubleSupplier)
        dataLogger.log("sup", (java.util.function.DoubleSupplier) $sup.get(object).getAsDouble());
                  ^
      method DataLogger.log(String,int) is not applicable
        (argument mismatch; DoubleSupplier cannot be converted to int)        
      method DataLogger.log(String,long) is not applicable
        (argument mismatch; DoubleSupplier cannot be converted to long)       
      method DataLogger.log(String,float) is not applicable
        (argument mismatch; DoubleSupplier cannot be converted to float)      
      method DataLogger.log(String,double) is not applicable
        (argument mismatch; DoubleSupplier cannot be converted to double)     
      method DataLogger.log(String,boolean) is not applicable
        (argument mismatch; DoubleSupplier cannot be converted to boolean)    
....
      method DataLogger.log(String,Enum<?>) is not applicable
        (argument mismatch; DoubleSupplier cannot be converted to Enum<?>)    
    where S#1,S#2,S#3,U are type-variables:
      S#1 extends Object declared in method <S#1>log(String,S#1,Struct<S#1>)  
      S#2 extends Object declared in method <S#2>log(String,S#2[],Struct<S#2>)
      S#3 extends Object declared in method <S#3>log(String,Collection<S#3>,Struct<S#3>)
      U extends Unit declared in method <U>log(String,Measure<U>,U)
  C:\Users\jashu\git\Epilogue_Supplier_Bug\build\generated\sources\annotationProcessor\java\main\frc\robot\RobotLogger.java:29: error: cannot find symbol   
        dataLogger.log("sup", (java.util.function.DoubleSupplier) $sup.get(object).getAsDouble());
                                                                              
    ^
    symbol:   method getAsDouble()
    location: class Object
  2 errors

The core issue is that the generated code tries to cast to a DoubleSupplier instead of to a double. My guess is this happens because some logic appends .getAsDouble without also noting the change in the cast. The code generated when sup is public does not need to cast.

  • Link to code:
package frc.robot;

import java.util.function.DoubleSupplier;

import edu.wpi.first.epilogue.Epilogue;
import edu.wpi.first.epilogue.Logged;
import edu.wpi.first.wpilibj.TimedRobot;

@Logged
public class Robot extends TimedRobot {
  private DoubleSupplier sup = ()->0;

  public Robot() {
    Epilogue.bind(this);
  }
}

Expected behavior
Successful compilation, as advertised in WPILib docs.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):
WPILib Information:
Project Version: 2025.1.1-beta-2
VS Code Version: 1.95.3
WPILib Extension Version: 2025.1.1-beta-2
C++ Extension Version: 1.22.9
Java Extension Version: 1.36.2024092708
Java Debug Extension Version: 0.58.2024090204
Java Dependencies Extension Version 0.24.0
Java Version: 17
Java Location: C:\Users\Public\wpilib\2025\jdk
Vendor Libraries:
WPILib-New-Commands (1.0.0)
Windows 11

@shueja shueja added the type: bug Something isn't working. label Nov 23, 2024
@shueja shueja changed the title [epilogue] Generation incorrect for logging private Supplier fields [epilogue] Generation order of operations incorrect for VarHandle cast with appended Supplier getAs* method Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

1 participant