visitTypeVariantNode method
Implementation
@override
void visitTypeVariantNode(TypeVariantNode node) {
assert(_currentContext is TypeDefinitionStatement);
final typeDefinitionStatement = _currentContext as TypeDefinitionStatement;
_context.addLast(node);
final variantClass = ClassBuilder(
name: node.name.lexeme,
withEquality: true,
)..final$ = true;
_pushClass(variantClass);
for (final parameter in node.parameters) {
parameter.accept(this);
}
if (_currentDefinitionTypes case final definitionTypes?) {
// If there's a single definition, it's going to be streamlined
if (typeDefinitionStatement.variants.length > 1) {
final currentVariantTypes = [
for (final parameter in node.parameters) resolver.annotations[parameter.type]!,
];
final typeParameters = _typeParametersFromTypeList(currentVariantTypes);
for (final type in definitionTypes) {
if (typeParameters.contains(type)) {
variantClass.addParameterToSupertype(
typeDefinitionStatement.name.lexeme,
type,
);
} else {
variantClass.addParameterToSupertype(
typeDefinitionStatement.name.lexeme,
const BottomType(),
);
}
}
}
}
_popClass();
_context.removeLast();
}