Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Bug Concatenation of non-empty String with value type causes a runtime exception

Discussion in 'Project Tiny' started by SINePrime, Mar 15, 2020.

  1. SINePrime

    SINePrime

    Joined:
    Jan 24, 2019
    Posts:
    54
    I'm getting an error when concatenating a non-empty string with a value type:
    [libil2cpp] String concatenation for objects of type System.Object is not supported.

    The behavior of concatenation is seemingly inconsistent, and I made 5 cases to test each case of concatenation.

    Code (CSharp):
    1.  
    2.       // passes
    3.       string concat1 = 1.ToString();
    4.       UnityEngine.Debug.Log("`1.ToString()` passes. You WILL see this message.");
    5.  
    6.       // passes
    7.       string concat2 = "" + 2.ToString();
    8.       UnityEngine.Debug.Log("`\"\" + 2.ToString()` passes. You WILL see this message.");
    9.      
    10.       // passes
    11.       string concat3 = "concat" + 3.ToString();
    12.       UnityEngine.Debug.Log("`\"concat\" + 3.ToString()` passes. You WILL see this message.");
    13.  
    14.       // exception
    15.       string concat4 = "concat" + 4;
    16.       UnityEngine.Debug.Log("`\"concat\" + 4` causes an exception. You WONT see this message.");
    17.      
    18.       // wont build
    19.       // error CS0656: Missing compiler required member 'System.String.Concat'
    20. //      string concat5 = "" + 5;
    21.  
    In case 4 it seems the value type is being implicitly treated as a System.Object, thus causing a runtime error. In case 5, this problem is correctly identified at build time: *error CS0656: Missing compiler required member 'System.String.Concat'*; but this problem is not identified at build time in case 4. What I would expect is builds to always fail when value types are implicitly treated as a System.Object (ie, case 4 should not build).
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    This is not a behavior I expect. Can you use the Unity bug reporter to submit a bug report? If so, please let me know the case number so that I can make sure the bug gets to the right place. I've tried this locally and cannot reproduce either the exception or the compile error, so I'd like to see the situation you have specifically.
     
  3. SINePrime

    SINePrime

    Joined:
    Jan 24, 2019
    Posts:
    54
    I completely forgot to mention this is a WebAssmbly build :oops:

    Regardless, I submitted the bug report; my case number is: `1228388`.
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Thanks, we will investigate this.
     
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    We were able to correct the behavior here. The fix is in Tiny 0.26 and later.
     
    SINePrime likes this.