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

Apply String declaration bounds to String conversion nodes #207

Closed
wants to merge 7 commits into from

Conversation

zcai1
Copy link

@zcai1 zcai1 commented Mar 24, 2022

Previously, string conversion node gets the same value as its operand has. This behavior is error prone because the annotations of its operand could be the supertypes of String's declaration bounds. This PR fixes such issue using the following rules:

  1. If the operand is a type variable and has no annotations, we apply its effective annotations instead.
  2. Otherwise, the operand should always have some annotations. For each annotation, if its a subtype of the string declaration bound in the same hierarchy, we add it to the result value; otherwise, we add the bound to the result value.

TypeMirror strType = n.getType();

Set<AnnotationMirror> operandAnnos = p.getValueOfSubNode(n.getOperand()).getAnnotations();
if (operandAnnos.isEmpty() && n.getOperand().getType().getKind() == TypeKind.TYPEVAR) {
Copy link
Member

Choose a reason for hiding this comment

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

What about wildcards?
Can you add test cases for both type variables and wildcards?
This change has no impact for the existing type systems, so can you add a simple test type system that illustrates the problem? How would a type system writer e.g. ensure that the operand type is not a supertype of the String declaration bound?

@zcai1
Copy link
Author

zcai1 commented Apr 1, 2022

double check the tests without the "nomsgtext" flag

zcai1 pushed a commit to zcai1/checker-framework that referenced this pull request Apr 4, 2022
@zcai1
Copy link
Author

zcai1 commented Jul 7, 2022

duplicate of eisop#213

@zcai1 zcai1 closed this Jul 7, 2022
@zcai1 zcai1 deleted the string-conversion-type branch July 7, 2022 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants