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

Binary Compatibility: Analyze type compatibility in assignments #181

Open
smarkwal opened this issue Jul 1, 2022 · 0 comments
Open

Binary Compatibility: Analyze type compatibility in assignments #181

smarkwal opened this issue Jul 1, 2022 · 0 comments
Labels
feature Feature request or idea

Comments

@smarkwal
Copy link
Owner

smarkwal commented Jul 1, 2022

If an expression is used to calculate a value which is then assigned to a local variable, a field, a method call argument, the expected return type of the expression should be assignment compatible with the type of the variable, field, or method parameter.

Unfortunately, getting the type of an expression is not simple. Most likely, this requires byte code and data flow analysis.

Example:

  • Class A has a static method "write" with a parameter of interface type java.io.Serializable.
  • Class B calls A.write(new DataObject()).
  • The expression new DataObject() returns a value of type DataObject.
  • In order for this code to work, the class type DataObject must implement the interface Serializable.

The byte code for the above logic would first create an instance of class DataObject, put a reference to this object onto the stack, call its constructor (<init>()), and then call the method A.write(Serializable) which will take the reference for the argument from the stack. This means that stack analysis is required to find the actual type of the argument value.

@smarkwal smarkwal added the feature Feature request or idea label Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or idea
Projects
None yet
Development

No branches or pull requests

1 participant