sb / smallbasic-editor

Home to the Small Basic editor (beta)
https://smallbasic-publicwebsite-code.azurewebsites.net/
MIT License
101 stars 34 forks source link

Primative Bug #185

Open VBAndCs opened 3 years ago

VBAndCs commented 3 years ago

While working on my Small Visual Basic, I discovered a bug in the Microsoft.SmallBasic.Library.Primitive class. When I call Primitive.IsArray on a variable that has a numeric value, it reserts its value to null. Tracing this bug, I found that IsArray calls ConstructArrayMap(), which initializes the _arrayMap: _arrayMap = new Dictionary<Primitive, Primitive>(PrimitiveComparer.Instance); before calling AsString char[] source = AsString.ToCharArray(); Un the AsString if _arrayMap is not null, the primative value is set to the string representaion of the array which is null:

        if (_arrayMap != null)
        {
            StringBuilder stringBuilder = new StringBuilder();
            foreach (KeyValuePair<Primitive, Primitive> item in _arrayMap)
            {
                stringBuilder.AppendFormat("{0}={1};", Escape(item.Key), Escape(item.Value));
            }
            _primitive = stringBuilder.ToString();
        }
VBAndCs commented 3 years ago

A possible fix is to make the _arrayMap check an elseif to be ignored if the promative has a numeric value

        elseif (_arrayMap != null)
        {