The following template crashes the code generator. Please have a look at the first line. I typed typ.dictionary.keyType. I wanted to type typ.dictionary.keyTypeName, but since keyType is a variable of dictionary, which is of the wrong type in this context, the code compiled, but with wrong types and then probably the exception during running the code generator was not caught.
{% macro convertType typ %}{% typed typ as TypeName %}{% if typ.isDictionary %}IMap<{% call convertType typ.dictionary.keyType %},{% call convertType typ.dictionary.valueTypeName %}>{% else %}{{ typ }}{% endif %}{% endmacro %}
<<<<<<<
{% for type in types.all %}
class {{ type.name }} {
{% for ivar in type.variables %}
final {% call convertType ivar.typeName %} _{{ ivar.name }};
{% endfor %}
}
{% endfor %}
|||||||
class Article {
final String _title;
final IMap<String,Section> _sections;
Article(this._title, this._sections);
// Technique: Copy "constructor" for concise partial updates
Article copy({String? title, IMap<String, Section>? sections}) => new Article(title ?? this._title, sections ?? this._sections);
@override String toString() => "Article(title=$_title, sections=$_sections)";
// Technique: Lenses for accessing/updating relevant properties
static final title = lensS<Article, String>((article) => article._title, (article, title) => article.copy(title: title));
static final sections = lensS<Article, IMap<String, Section>>((article) => article._sections, (article, sections) => article.copy(sections: sections));
static final section = (String id) => sections.andThenE<Section, String>(imapLensE(id, () => "No section '$id'"));
}
>>>>>>>
The following template crashes the code generator. Please have a look at the first line. I typed
typ.dictionary.keyType
. I wanted to typetyp.dictionary.keyTypeName
, but sincekeyType
is a variable ofdictionary
, which is of the wrong type in this context, the code compiled, but with wrong types and then probably the exception during running the code generator was not caught.