Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

out char arguments don't get boxed correctly. #949

Open
otac0n opened this issue Feb 12, 2016 · 3 comments
Open

out char arguments don't get boxed correctly. #949

otac0n opened this issue Feb 12, 2016 · 3 comments
Labels

Comments

@otac0n
Copy link

otac0n commented Feb 12, 2016

public void A()
{
    char c;
    if (!this.B(out c) && c == ':')
    {
        return;
    }
    return;
}

public bool B(out char c)
{
    c = ':';
    return true;
}
  function Class1_A () {
    var c = String.fromCharCode(new JSIL.BoxedVariable("\x00"));
    var flag = !this.B(/* ref */ c) && 
    (((c.get()).charCodeAt(0) | 0) === ((":").charCodeAt(0) | 0));
    if (flag) {
    }
  }; 

  function Class1_B (/* ref */ c) {
    c.set((":").charCodeAt(0));
    return true;
  }; 

notabox

@kg kg added the Bug label Feb 12, 2016
@otac0n
Copy link
Author

otac0n commented Feb 17, 2016

In IntroduceVariableReferences, I see this comment:

var newDeclaration = new JSVariableDeclarationStatement(new JSBinaryOperatorExpression(
    JSOperator.Assignment,
    // We have to use a constructed ref to the variable here, otherwise
    //  the declaration will look like 'var x.value = foo'
    new JSVariable(variable.Identifier, variable.IdentifierType, variable.Function),
    JSIL.NewReference(initialValue), 
    newVariable.IdentifierType
));

While in IntroduceCharCasts, I see this logic:

if (boe.Operator == JSOperator.Assignment && (leftType.FullName == "System.Char") && (rightType.FullName != "System.Char"))
{
    boe.ReplaceChild(boe.Right, CastToChar(boe.Right));
}
if (boe.Operator == JSOperator.Assignment && (leftType.FullName != "System.Char") && (rightType.FullName == "System.Char"))
{
    boe.ReplaceChild(boe.Right, CastToInteger(boe.Right));
}

The problem here being that the right type for the assignment is System.Char&.

Any suggestions for a fix?

@otac0n
Copy link
Author

otac0n commented Feb 17, 2016

So, for my purposes, just ignoring the warning seems to have fixed it:

var newDeclaration = new JSVariableDeclarationStatement(new JSBinaryOperatorExpression(
    JSOperator.Assignment,
    newVariable,
    JSIL.NewReference(initialValue), 
    newVariable.IdentifierType
));

Contrary to the warning, the code that gets generated now looks like this:

  function Class1_A () {
    var c = new JSIL.BoxedVariable("\x00");
    if (!$thisType.B(/* ref */ c)) {
      return;
    }
  }; 

  function Class1_B (/* ref */ c) {
    c.set(":");
    return true;
  }; 

@kg
Copy link
Member

kg commented Feb 17, 2016

The problem here being that the right type for the assignment is System.Char&.

Stripping the reference part of the type is probably okay here. Maybe try that. There's a method in TypeUtil that does it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants