Skip to content

Commit

Permalink
https://github.com/manifold-systems/manifold/issues/573
Browse files Browse the repository at this point in the history
- fix issue with using a binding expression in a ternary expression
  • Loading branch information
rsmckinney committed May 6, 2024
1 parent 8649da5 commit d377e49
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ default void setResult( JCTree.JCExpression tree, Type owntype, String valVar )

default ArrayList<Node<JCExpression, Tag>> getBindingOperands( JCExpression tree, ArrayList<Node<JCExpression, Tag>> operands )
{
if( tree instanceof JCBinary && tree.getTag() == Tag.APPLY )
if( tree instanceof JCBinary && tree.getTag() == Tag.NO_TAG )
{
// Binding expr

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ public class ManAttr_11 extends Attr implements ManAttr
return;
}

if( tree.getTag() == JCTree.Tag.APPLY ) // binding expr
if( tree.getTag() == JCTree.Tag.NO_TAG ) // binding expr
{
// Handle binding expressions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ public class ManAttr_17 extends Attr implements ManAttr
return;
}

if( tree.getTag() == JCTree.Tag.APPLY ) // binding expr
if( tree.getTag() == JCTree.Tag.NO_TAG ) // binding expr
{
// Handle binding expressions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ public void visitBinary( JCTree.JCBinary tree )
return;
}

if( tree.getTag() == JCTree.Tag.APPLY ) // binding expr
if( tree.getTag() == JCTree.Tag.NO_TAG ) // binding expr
{
// Handle binding expressions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,10 @@ public class ManJavacParser extends JavacParser
JCExpression od1,
JCExpression od2)
{
//Manifold: use APPLY for binding op.
//Manifold: use NO_TAG for binding op.
//It is later changed to MUL after ManAttr processing so the expr will pass safely through javac until it is
//transformed to a pre/postBind() call.
JCTree.Tag optag = topOp == null ? JCTree.Tag.APPLY : optag( topOp );
JCTree.Tag optag = topOp == null ? JCTree.Tag.NO_TAG : optag( topOp );

return F.at( pos ).Binary( optag, od1, od2 );
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ public void testInArgOfOverload()
assertEquals( Rational.get( 5 ).toString(), (5r).toString() );
}

@Test
public void testCanBeStatement()
{
10 k;
}

@Test
public void testStorage()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package manifold.science.regression;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class UnitExpressionInTernaryBranchTest
{
@Test
public void testUnitExpressionInTernaryBranch()
{
ByteCoercion bt = ByteCoercion.INSTANCE;
int i = 1;
byte bb = i > 0 ? 2bt : (byte)1;
assertEquals( 2bt, bb );
}

public static class ByteCoercion
{
static final ByteCoercion INSTANCE = new ByteCoercion();

public byte postfixBind( int value )
{
return (byte)value;
}
}
}

0 comments on commit d377e49

Please sign in to comment.