"Invalid character literal" on compile

It seems I am getting Invalid character literalwhen compiling my code sometimes. It failes on the first ein WriteLine, which is very weird. Earlier I got in on the l in another function, can’t remember which right now.

System.Console.WriteLine('value');

Hi Jo Emil,

'' is for characters, "" is for strings. So you need to change 'value' to "value" in this case.

(Also, you want debug_log, instead of System.Console.WriteLine, but we discussed that in another channel already.)

Ah, that makes sense. Though, quite weird that the error pointed out what looked like random places in the syntax.

Can you post a full example where the error is reported to be in the wrong place? I just tried

  1 using Uno;
  2
  3 namespace SourceOff
  4 {
  5     public class App : Application
  6     {
  7         void f()
  8         {
  9             System.Console.WriteLine('value');
 10         }
 11     }
 12 }

And it reports the error to be at App.uno(9,38):, which is the beginning of value.

using Uno;
using Fuse;
using Fuse.Resources;
using Fuse.Triggers;
using Fuse.Controls;
using Fuse.Gestures;
using Uno.Data.Json;

public partial class MainView
{
    public MainView()
    {
        InitializeUX();

        var json = JsonReader.Parse(import BundleFile("Assets/pricelist.json").ReadAllText());

        for (int i = 0; i < json["services"].Count; i++) {
            var obj = json["services"][i];

            debug_log foo["title"].AsString();
        }

        System.Console.WriteLine('value');
    }
}

This gave me the error at 23:28, which would be the first e in WriteLine.

It seems this issue is due to how Sublime Text uses “Column” when you use tabs for indentation. If you have <tab>x in Sublime, it will report x as being in column 5, even though it is actually in colum 2 in the document (which is what other editors like vim and Emacs correctly display).

The fact that it is displayed in column 5 is just an artifact of the tabSize setting in sublime. There is no way for the compiler to know this, so I’m afraid it’s hard to compensate for.

The only workaround I can think of is to use spaces for indentation instead of tabs, which you can do using the translateTabsToSpaces setting in Sublime.

Ah, that makes sense :slight_smile:

Thanks!