This PR improves the error messages when a record cannot conform to a typeclass, because it has fields of types that don’t. In addition, it generates the C++ operator<< for enums, and introduces the show typeclass to do the same for records deriving (show).
This PR allows you to write the following C++ code:
Product p{"Little Red Corvette", "v0KpfrJE4zw", Amount{1999, CurrencyCode::USD}};
Product q{"Breakfast Can Wait", "CzWX1gv6u2s", Amount{2013, CurrencyCode::EUR}};
ShoppingCart c{{p, q}};
std::cout << c << std::endl;
/* prints
"""ShoppingCart{ items:[
Product{ name:Little Red Corvette, identifier:v0KpfrJE4zw, price:Amount{ units:1999, currency:CurrencyCode::USD } },
Product{ name:Breakfast Can Wait, identifier:CzWX1gv6u2s, price:Amount{ units:2013, currency:CurrencyCode::EUR } },
] }"""
*/
If Amount would be missing the declaration of conformance to show, the error message from running Djinni would clearly say so:
Record 'Amount' not deriving required operation(s): 'show'
Supported Field Types
any record deriving (show)
numbers and strings
any enum
any list<T> where T is any of the above (or a map, or a list)
any map<K,V> where K and V are any of the above (or a map)
Limitations/Known Issues
data fields are printed as arrays of integers by default
flag and optional fields require handwritten overloads of operator<< to be available in the translation unit of the record; failure to do so will not report an error until trying to compile the record’s .cppfile
no specific error checking/reporting is implemented for containers: if the contained type doesn’t support show, the error may not surface until trying to compile the record’s .cpp file
the added code is most definitely not idiomatic Scala, but rather baby steps towards learning the language
This PR improves the error messages when a record cannot conform to a typeclass, because it has fields of types that don’t. In addition, it generates the C++
operator<<
for enums, and introduces theshow
typeclass to do the same for recordsderiving (show)
.Assuming the following Djinni file:
This PR allows you to write the following C++ code:
If
Amount
would be missing the declaration of conformance toshow
, the error message from running Djinni would clearly say so:Supported Field Types
deriving (show)
enum
list<T>
whereT
is any of the above (or a map, or a list)map<K,V>
whereK
andV
are any of the above (or a map)Limitations/Known Issues
data
fields are printed as arrays of integers by defaultflag
andoptional
fields require handwritten overloads ofoperator<<
to be available in the translation unit of the record; failure to do so will not report an error until trying to compile the record’s.cpp
fileshow
, the error may not surface until trying to compile the record’s.cpp
file