Exemple #1
0
 public SetUpContext(Tpn.TypeProblem2.Builder typeProblem) : this(typeProblem, Possibly.IsNot <ISetUpContext>(), Possibly.IsNot <ISetUp>())
 {
 }
Exemple #2
0
 private SetUpContext(Tpn.TypeProblem2.Builder typeProblem, IIsPossibly <ISetUpContext> parent, IIsPossibly <ISetUp> enclosingSetUp)
 {
     TypeProblem    = typeProblem ?? throw new ArgumentNullException(nameof(typeProblem));
     Parent         = parent ?? throw new ArgumentNullException(nameof(parent));
     EnclosingSetUp = enclosingSetUp ?? throw new ArgumentNullException(nameof(enclosingSetUp));
 }
Exemple #3
0
        private OrType <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> > ConvertType(
            Tpn.TypeProblem2.Builder problem,
            Tpn.IStaticScope scope,
            IOrType <IVerifiableType, IError> typeOrError)
        {
            return(typeOrError.SwitchReturns(type =>
            {
                if (type is NumberType numberType)
                {
                    return OrType.Make <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> >(new NameKey("number"));
                }
                else if (type is EmptyType emptyType)
                {
                    return OrType.Make <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> >(new NameKey("empty"));
                }
                else if (type is BooleanType booleanTyp)
                {
                    return OrType.Make <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> >(new NameKey("bool"));
                }
                else if (type is BlockType blockType)
                {
                    throw new Exception("can't be asked");
                }
                else if (type is StringType stringType)
                {
                    return OrType.Make <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> >(new NameKey("string"));
                }
                else if (type is AnyType anyType)
                {
                    throw new Exception("can't be asked");
                }

                if (type is InterfaceType interfaceType)
                {
                    if (!typeCache.TryGetValue(type, out var res))
                    {
                        return OrType.Make <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> >(OrType.Make <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError>(res !));
                    }

                    // we don't know the type key...
                    var tpnType = problem.CreateTypeExternalType(scope, new WeakTypeDefinitionConverter(), interfaceType);
                    typeCache[type] = tpnType;
                    var orType = OrType.Make <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError>(tpnType);
                    foreach (var memberPair in interfaceType.Members)
                    {
                        var innerType = ConvertType(problem, tpnType, OrType.Make <IVerifiableType, IError>(memberPair.Type));
                        innerType.Switch(x =>
                        {
                            problem.CreatePublicMember(tpnType, tpnType, memberPair.Key, OrType.Make <IKey, IError>(x));
                        }, y =>
                        {
                            problem.CreatePublicMember(tpnType, memberPair.Key, y);
                        });
                    }
                    return OrType.Make <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> >(orType);
                }
                else if (type is TypeOr typeOr)
                {
                    throw new Exception("i don't want to think about it");
                }
                else if (type is TypeAnd typeAnd)
                {
                    throw new Exception("i don't want to think about it");
                }
                else if (type is MethodType methodType)
                {
                    var input = ConvertType(problem, scope, OrType.Make <IVerifiableType, IError>(methodType.InputType));
                    var output = ConvertType(problem, scope, OrType.Make <IVerifiableType, IError>(methodType.OutputType));
                    if (input.Is2(out var i2) && output.Is2(out var o2))
                    {
                        problem.GetMethod(i2, o2);
                    }
                    else if (input.Is1(out var i1) && output.Is1(out var o1))
                    {
                        return OrType.Make <IKey, IOrType <Tpn.TypeProblem2.MethodType, Tpn.TypeProblem2.Type, Tpn.TypeProblem2.Object, Tpn.TypeProblem2.OrType, Tpn.TypeProblem2.InferredType, Tpn.TypeProblem2.GenericTypeParameter, IError> >(new GenericNameKey(new NameKey("method"), new IOrType <IKey, IError>[] {
                            OrType.Make <IKey, IError>(i1), OrType.Make <IKey, IError>(o1)
                        }));
                    }