public NoSuchIndexerException(RelinqScriptExpression root, IndexerExpression ie, RelinqScriptType typeOfTarget) : base(JSToCSharpExceptionType.NoSuchIndexer, root, ie) { InferredTypeOfTarget = typeOfTarget; }
private void InferIndexer(IndexerExpression ie, TypeInferenceCache cache) { InferTypes(ie.Target, cache); var typeofTarget = cache[ie.Target]; if (typeofTarget is ClrType) { var preview = cache.Clone(); ie.Operands.ForEach(operand => InferTypes(operand, preview)); var types = ie.Operands.Select(operand => preview[operand]); if (types.Any(type => type is Variant)) { cache.Add(ie, new Variant()); cache.Upgrade(preview); } else { var alts = typeofTarget.LookupIndexers(); if (alts == null) { throw new NoSuchIndexerException(Root, ie, typeofTarget); } InferMethodGroup(alts, ie, cache); } } else if (typeofTarget is Variant) { cache.Add(ie, new Variant()); } else { throw new NoSuchIndexerException(Root, ie, typeofTarget); } }
private LinqExpression CompileIndexer(IndexerExpression ie, CompilationContext ctx) { var typeofTarget = ctx.Types[ie.Target]; if (typeofTarget is ClrType) { var clrType = ((ClrType)typeofTarget).Type; if (clrType.IsArray && clrType.GetArrayRank() == 1) { // not checking whether the indexer expression has one and only operand return LinqExpression.ArrayIndex( Compile(ie.Target, ctx), CompileCallArguments(ctx.Invocations[ie], ie.Operands, ctx)); } else { // not checking for a void-returning signature // neither we check whether the sig is actually an indexer return LinqExpression.Call( Compile(ie.Target, ctx), ctx.Invocations[ie].Signature, CompileCallArguments(ctx.Invocations[ie], ie.Operands, ctx)); } } else { throw new CSharpBuilderException( JSToCSharpExceptionType.UnexpectedInferredAst, Ast, ie, ctx); } }