qwertie / ecsharp

Home of LoycCore, the LES language of Loyc trees, the Enhanced C# parser, the LeMP macro preprocessor, and the LLLPG parser generator.
http://ecsharp.net
Other
172 stars 25 forks source link

EC#: [return: ...] attribute sometimes causes IndexOutOfRangeException in InternalList #137

Open qwertie opened 3 years ago

qwertie commented 3 years ago

Example case:

[return: MaybeNull]
public static T LastOrDefault<T>(this IListAndListSource<T> list, [AllowNull] T defaultValue = default(T)) =>
    LastOrDefault((IList<T>)list, defaultValue);
[return: MaybeNull] // Causes internal error
public static T FirstOrDefault<T>(this IListAndListSource<T> list, [AllowNull] T defaultValue = default(T)) =>
    FirstOrDefault((IList<T>)list, defaultValue);

Remarkably the first one is fine but the second one causes an error. Workaround: use #rawText

[return: MaybeNull]
public static T LastOrDefault<T>(this IListAndListSource<T> list, [AllowNull] T defaultValue = default(T)) =>
    LastOrDefault((IList<T>)list, defaultValue);
#rawText("[return: MaybeNull]");
public static T FirstOrDefault<T>(this IListAndListSource<T> list, [AllowNull] T defaultValue = default(T)) =>
    FirstOrDefault((IList<T>)list, defaultValue);