Broken scripts (And workaround(

Thomas Diemar Bennedsen shared this bug 11 days ago
Reported

Latest update broke scripts that use interfaces and/abstract classes


This fails:

public abstract class AbtractTest

{

//Fails with "'return type must be List<string>..'"

public abstract List<string> getStrings();

//Fails with "'return type must be Dictionary<string, string>..'"

public abstract Dictionary<string, string> getStringDict();

//Fails with no error message (blank popup)

public abstract System.Collections.Generic.List<IMyTerminalBlock> getBlocks();

}


public interface InterfaceTest

{

//Fails with "'return type must be List<string>..'"

List<string> getStrings();

//Fails with "'return type must be Dictionary<string, string>..'"

Dictionary<string, string> getStringDict();

//Fails with no error message (blank popup)

System.Collections.Generic.List<IMyTerminalBlock> getBlocks();

}


Workaround:

Implement wrapper class for all returntypes of interface/abstract class


public class WrapperStringList : List<string> { }

public class WrapperDictionary : Dictionary<string, string> { }

public class WrapperIMyTerminalBlockList : List<IMyTerminalBlock> { }


public abstract class AbtractWorkaroundTest

{

public abstract WrapperStringList getStrings();

public abstract WrapperDictionary getStringDict();

public abstract WrapperIMyTerminalBlockList getBlocks();

}


public interface InterfaceWorkaroundTest

{

WrapperStringList getStrings();

WrapperDictionary getStringDict();

WrapperIMyTerminalBlockList getBlocks();

}


public class AbtractWorkaroundTestImpl : AbtractWorkaroundTest

{

public override WrapperIMyTerminalBlockList getBlocks()

{

return new WrapperIMyTerminalBlockList { { default(IMyTerminalBlock) } };

}


public override WrapperDictionary getStringDict()

{

return new WrapperDictionary { { "test", "test" } };

}


public override WrapperStringList getStrings()

{

return new WrapperStringList { "test" };

}

}


public class InterfaceWorkaroundTestImpl : InterfaceWorkaroundTest

{

public WrapperIMyTerminalBlockList getBlocks()

{

return new WrapperIMyTerminalBlockList { { default(IMyTerminalBlock) } };

}


public WrapperDictionary getStringDict()

{

return new WrapperDictionary { { "test", "test" } };

}


public WrapperStringList getStrings()

{

return new WrapperStringList { "test" };

}

}


public void Main(string argument, UpdateType updateType)

{

var abstracttest = new AbtractWorkaroundTestImpl();


List<string> list = abstracttest.getStrings();

Echo(list[0]);


Dictionary<string, string> dict = abstracttest.getStringDict();

Echo(dict["test"]);


List<IMyTerminalBlock> blocklist = abstracttest.getBlocks();

Echo("isdefault:"+(blocklist[0] == default(IMyTerminalBlock)));


var interfacetest = new InterfaceWorkaroundTestImpl();


List<string> list2 = abstracttest.getStrings();

Echo(list2[0]);


Dictionary<string, string> dict2 = abstracttest.getStringDict();

Echo(dict2["test"]);


List<IMyTerminalBlock> blocklist2 = abstracttest.getBlocks();

Echo("isdefault:" + (blocklist2[0] == default(IMyTerminalBlock)));

}


I have more that 388000 lines of code. Either i will stop playing SE until Keen fixes this, or I will return with a Parser that parses script and fixes this.

Replies (5)

photo
1

Please paste your code in code blocks. This is a mess to try and read.

photo
1

 public abstract class AbtractTest
 {
     //Fails with "'return type must be List<string>..'" 
     public abstract List<string> getStrings();
     //Fails with "'return type must be Dictionary<string, string>..'" 
     public abstract Dictionary<string, string> getStringDict();
     //Fails with no error message (blank popup)
     public abstract System.Collections.Generic.List<IMyTerminalBlock> getBlocks();
 }

 public interface InterfaceTest
 {
     //Fails with "'return type must be List<string>..'" 
     List<string> getStrings();
     ////Fails with "'return type must be Dictionary<string, string>..'"
     Dictionary<string, string> getStringDict();
     ////Fails with no error message (blank popup)
     System.Collections.Generic.List<IMyTerminalBlock> getBlocks();
 }
    
 //Workaround:

 public class WrapperStringList : List<string> { }
 public class WrapperDictionary : Dictionary<string, string> { }
 public class WrapperIMyTerminalBlockList : List<IMyTerminalBlock> { }

 public abstract class AbtractWorkaroundTest
 {
     public abstract WrapperStringList getStrings();
     public abstract WrapperDictionary getStringDict();
     public abstract WrapperIMyTerminalBlockList getBlocks();
 }

 public interface InterfaceWorkaroundTest
 {
     WrapperStringList getStrings();
     WrapperDictionary getStringDict();
     WrapperIMyTerminalBlockList getBlocks();
 }

 public class AbtractWorkaroundTestImpl : AbtractWorkaroundTest
 {
     public override WrapperIMyTerminalBlockList getBlocks()
     {
         return new WrapperIMyTerminalBlockList { { default(IMyTerminalBlock) } };
     }

     public override WrapperDictionary getStringDict()
     {
         return new WrapperDictionary { { "test", "test" } };
     }

     public override WrapperStringList getStrings()
     {
         return new WrapperStringList { "test" };
     }
 }

 public class InterfaceWorkaroundTestImpl : InterfaceWorkaroundTest
 {
     public WrapperIMyTerminalBlockList getBlocks()
     {
         return new WrapperIMyTerminalBlockList { { default(IMyTerminalBlock) } };
     }

     public WrapperDictionary getStringDict()
     {
         return new WrapperDictionary { { "test", "test" } };
     }

     public WrapperStringList getStrings()
     {
         return new WrapperStringList { "test" };
     }
 }

 public void Main(string argument, UpdateType updateType)
 {
     var abstracttest = new AbtractWorkaroundTestImpl();

     List<string> list = abstracttest.getStrings();
     Echo(list[0]);

     Dictionary<string, string> dict = abstracttest.getStringDict();
     Echo(dict["test"]);

     List<IMyTerminalBlock> blocklist = abstracttest.getBlocks();
     Echo("isdefault:"+(blocklist[0] == default(IMyTerminalBlock)));

     var interfacetest = new InterfaceWorkaroundTestImpl();

     List<string> list2 = abstracttest.getStrings();
     Echo(list2[0]);

     Dictionary<string, string> dict2 = abstracttest.getStringDict();
     Echo(dict2["test"]);

     List<IMyTerminalBlock> blocklist2 = abstracttest.getBlocks();
     Echo("isdefault:" + (blocklist2[0] == default(IMyTerminalBlock)));
 }

photo
1

Hello, Engineer!


Thank you for the provided script.

We've added your report it to our internal ticket on this topic.

We will update this thread when we have more information.


Kind Regards

Keen Software House

photo
1

I think we are having the same issue. One of our most-used scripts broke after the update. I ablated the code and narrowed it down to operations on Dictionaries, but had no idea how to fix it. Thanks for posting the workaround! Hopefully, this will get fixed properly.

photo
1

Better "workaround"

If applicable use inherited inferfaces
 public abstract class AbtractTest
 {
     ////Fails with "'return type must be List<string>..'" 
     //public abstract List<string> getStrings();
     ////Fails with "'return type must be Dictionary<string, string>..'" 
     //public abstract Dictionary<string, string> getStringDict();
     ////Fails with no error message (blank popup)
     //public abstract System.Collections.Generic.List<IMyTerminalBlock> getBlocks();

     public abstract IDictionary<string, string> getStringDict();

     public abstract IEnumerable<string> getStrings();
 }

 public interface InterfaceTest
 {
     ////Fails with "'return type must be List<string>..'" 
     //List<string> getStrings();
     ////Fails with "'return type must be Dictionary<string, string>..'"
     //Dictionary<string, string> getStringDict();
     ////Fails with no error message (blank popup)
     //System.Collections.Generic.List<IMyTerminalBlock> getBlocks();

     //IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>

     IDictionary<string, string> getStringDict();

     IEnumerable<string> getStrings();
 }


 public class AbtractWorkaroundTestImpl : AbtractTest
 {

     //public override List<IMyTerminalBlock> getBlocks()
     //{
     //    return new List<IMyTerminalBlock> { { default(IMyTerminalBlock) } };
     //}

     //public override Dictionary<string, string> getStringDict() { 

     //    return new Dictionary<string, string> { { "test", "test" } };
     //}

     //public override List<string> getStrings()
     //{
     //    return new List<string> { "test" };
     //}
     public override IDictionary<string, string> getStringDict()
     {
         return new Dictionary<string, string> { { "test", "test" } };
     }


     public override IEnumerable<string> getStrings()
     {
         return new List<string> { "test" };
     }
 }

 public class InterfaceWorkaroundTestImpl : InterfaceTest
 {

     //public List<IMyTerminalBlock> getBlocks()
     //{
     //    return new List<IMyTerminalBlock> { { default(IMyTerminalBlock) } };
     //}

     //public Dictionary<string, string> getStringDict()
     //{
     //    return new Dictionary<string, string> { { "test", "test" } };
     //}

     //public List<string> getStrings()
     //{
     //    return new List<string> { "test" };
     //}
     //
     //
     public IDictionary<string, string> getStringDict()
     {
         return new Dictionary<string, string> { { "test", "test" } };
     }

     public IEnumerable<string> getStrings()
     {
         return new List<string> { "test" };
     }
 }

 public void Main(string argument, UpdateType updateType)
 {
     var abstracttest = new AbtractWorkaroundTestImpl();

     //List<string> list = abstracttest.getStrings();
     //Echo(list[0]);

     //Dictionary<string, string> dict = abstracttest.getStringDict();
     //Echo(dict["test"]);

     //List<IMyTerminalBlock> blocklist = abstracttest.getBlocks();
     //Echo("isdefault:"+(blocklist[0] == default(IMyTerminalBlock)));

     var dict = abstracttest.getStringDict();
     Echo(dict["test"]);

     var list = abstracttest.getStrings();
     Echo(list.FirstOrDefault());

     var interfacetest = new InterfaceWorkaroundTestImpl();

     //List<string> list2 = interfacetest.getStrings();
     //Echo(list2[0]);

     //Dictionary<string, string> dict2 = interfacetest.getStringDict();
     //Echo(dict2["test"]);

     //List<IMyTerminalBlock> blocklist2 = interfacetest.getBlocks();
     //Echo("isdefault:" + (blocklist2[0] == default(IMyTerminalBlock)));

     var dict2 = interfacetest.getStringDict();
     Echo(dict2["test"]);

     var list2 = interfacetest.getStrings();
     Echo(list2.FirstOrDefault());
 }

Leave a Comment
 
Attach a file