public override IAssignEmitter AssignFrom(ModuleContext context, TO2Type otherType) { RealizedType underlyingOther = otherType.UnderlyingType(context); return(!(underlyingOther is OptionType) && elementType.IsAssignableFrom(context, underlyingOther) ? new AssignSome(this, otherType) : DefaultAssignEmitter.Instance); }
public override bool IsAssignableFrom(ModuleContext context, TO2Type otherType) { if (!(otherType.UnderlyingType(context) is TupleType)) { return(false); } return(GeneratedType(context).IsAssignableFrom(otherType.GeneratedType(context))); }
public override bool IsAssignableFrom(ModuleContext context, TO2Type otherType) { if (otherType.UnderlyingType(context) is OptionType otherOption) { return(elementType.IsAssignableFrom(context, otherOption.elementType)); } return(elementType.IsAssignableFrom(context, otherType)); }
public override bool IsAssignableFrom(ModuleContext context, TO2Type otherType) { if (otherType.UnderlyingType(context) is ResultType otherResultType) { return(successType.IsAssignableFrom(context, otherResultType.successType) && errorType.IsAssignableFrom(context, otherResultType.errorType)); } return(successType.IsAssignableFrom(context, otherType)); }
public override RealizedType UnderlyingType(ModuleContext context) { if (lookingUp) { throw new CompilationErrorException(new List <StructuralError> { new StructuralError( StructuralError.ErrorType.InvalidType, $"Cyclic dependency to {aliasedType.Name}", target.Start, target.End ) }); } lookingUp = true; RealizedType realized = aliasedType.UnderlyingType(declaredModule); lookingUp = false; return(realized); }
public override bool IsAssignableFrom(ModuleContext context, TO2Type otherType) { RecordType recordType = otherType.UnderlyingType(context) as RecordType; if (recordType == null) { return(false); } foreach (var kv in ItemTypes) { TO2Type otherItem = recordType.ItemTypes.Get(kv.Key); if (otherItem == null || !kv.Value.IsAssignableFrom(context, otherItem)) { return(false); } } return(true); }
public IOperatorEmitter GetMatching(ModuleContext context, Operator op, TO2Type otherType) { IOperatorEmitter existing = allowedOperators.GetMatching(context, op, otherType); if (existing != null) { return(existing); } if (op != Operator.BitAnd && op != Operator.BitAndAssign) { return(null); } RecordType otherRecordType = otherType.UnderlyingType(context) as RecordType; if (otherRecordType == null) { return(null); } bool hasMatch = false; foreach (var otherKV in otherRecordType.ItemTypes) { TO2Type item = recordType.ItemTypes.Get(otherKV.Key); if (item == null) { continue; } if (!item.IsAssignableFrom(context, otherKV.Value)) { return(null); } hasMatch = true; } return(hasMatch ? recordType.CombineFrom(otherRecordType) : null); }
public override RealizedType UnderlyingType(ModuleContext context) => new OptionType(elementType.UnderlyingType(context));
public override RealizedType UnderlyingType(ModuleContext context) => new FunctionType(isAsync, parameterTypes.Select(p => p.UnderlyingType(context) as TO2Type).ToList(), returnType.UnderlyingType(context));
public override RealizedType UnderlyingType(ModuleContext context) => new ResultType(successType.UnderlyingType(context), errorType.UnderlyingType(context));