diff --git a/src/utils/object_serializer.cr b/src/utils/object_serializer.cr index 1f53caf07..b487c2609 100644 --- a/src/utils/object_serializer.cr +++ b/src/utils/object_serializer.cr @@ -37,7 +37,7 @@ module Mint Codegen.join ["((_)=>", js.class_of(node.name), ".encode(_))"] end - def encoder(node : TypeChecker::Variable) + def encoder(node : TypeChecker::Variable) : Codegen::Node # This should never happen because of the typechecker! raise "Cannot generate an encoder for a type variable!" end @@ -47,11 +47,20 @@ module Mint when "Time" "Encoder.time" when "Array" - "Encoder.array(#{encoder(node.parameters.first)})" + item_encoder = + (encoder(node.parameters.first) || "").as(Codegen::Node) + + Codegen.join ["Encoder.array(", item_encoder, ")"] when "Maybe" - "Encoder.maybe(#{encoder(node.parameters.first)})" + item_encoder = + (encoder(node.parameters.first) || "").as(Codegen::Node) + + Codegen.join ["Encoder.maybe(", item_encoder, ")"] when "Map" - "Encoder.map(#{encoder(node.parameters.last)})" + item_encoder = + (encoder(node.parameters.last) || "").as(Codegen::Node) + + Codegen.join ["Encoder.map(", item_encoder, ")"] end end