Skip to content

Commit

Permalink
Fix Default<G>()
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-aws committed Mar 4, 2020
1 parent f60634f commit 2ece678
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion Binaries/DafnyRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,13 @@ public partial class Helpers {
System.Console.Write(ToString(g));
}
public static G Default<G>() {
System.Type ty = typeof(G);
Type ty = typeof(G);
// TODO-RS: How to generalize this?
if (ty.Name.Equals("ISequence`1")) {
Type classType = Type.GetType("Dafny.Sequence`1");
Type parameterizedClassType = classType.MakeGenericType(ty.GenericTypeArguments);
ty = parameterizedClassType;
}
System.Reflection.MethodInfo mInfo = ty.GetMethod("_DafnyDefaultValue");
if (mInfo != null) {
G g = (G)mInfo.Invoke(null, null);
Expand Down
8 changes: 7 additions & 1 deletion Source/DafnyRuntime/DafnyRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,13 @@ public partial class Helpers {
System.Console.Write(ToString(g));
}
public static G Default<G>() {
System.Type ty = typeof(G);
Type ty = typeof(G);
// TODO-RS: How to generalize this?
if (ty.Name.Equals("ISequence`1")) {
Type classType = Type.GetType("Dafny.Sequence`1");
Type parameterizedClassType = classType.MakeGenericType(ty.GenericTypeArguments);
ty = parameterizedClassType;
}
System.Reflection.MethodInfo mInfo = ty.GetMethod("_DafnyDefaultValue");
if (mInfo != null) {
G g = (G)mInfo.Invoke(null, null);
Expand Down

0 comments on commit 2ece678

Please sign in to comment.