Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Compilation of subset types constrained by type parameter #3893

Merged
merged 15 commits into from
May 4, 2023
Prev Previous commit
Next Next commit
fix: Add cast required by Java for functions
Fixes #3892
  • Loading branch information
RustanLeino committed Apr 21, 2023
commit 59e1a3221cd650085da0f9ab778bc0e691a02041
6 changes: 5 additions & 1 deletion Source/DafnyCore/Compilers/Java/Compiler-java.cs
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ protected class ClassWriter : IClassWriter {
// we're looking for).
var tp = targetTypeIgnoringConstraints.AsTypeParameter;
if (tp == null) {
typeDescriptorExpr = $"{DafnyTypeDescriptor}.referenceWithInitializer({StripTypeParameters(targetTypeName)}.class, () -> {d})";
typeDescriptorExpr = $"{DafnyTypeDescriptor}.referenceWithInitializer({StripTypeParameters(targetTypeName)}.class, () -> ({targetTypeName}){d})";
} else {
var td = FormatTypeDescriptorVariable(tp.GetCompileName(Options));
typeDescriptorExpr = $"{DafnyTypeDescriptor}.referenceWithInitializerAndTypeDescriptor({td}, () -> {d})";
Expand Down Expand Up @@ -3128,6 +3128,10 @@ protected class ClassWriter : IClassWriter {
return $"({BoxedTypeName(xType, wr, udt.tok)}) null";
}
} else if (cl is DatatypeDecl dt) {
if (DatatypeWrapperEraser.GetInnerTypeOfErasableDatatypeWrapper(Options, dt, out var innerType)) {
var typeSubstMap = TypeParameter.SubstitutionMap(dt.TypeArgs, udt.TypeArgs);
return TypeInitializationValue(innerType.Subst(typeSubstMap), wr, tok, usePlaceboValue, constructTypeParameterDefaultsFromTypeDescriptors);
}
var s = FullTypeName(udt);
var typeargs = "";
var nonGhostTypeArgs = SelectNonGhost(cl, udt.TypeArgs);
Expand Down