public override void CheckSemantics(Scope scope, ErrorReporter report) { base.CheckSemantics(scope, report); var variableInfo = scope.ResolveVarOrFunction(MainIDNode.Text) as VariableInfo; if (report.Assert(this, variableInfo != null, "Unknown variable for the current scope ({0}).", MainIDNode.Text)) { Debug.Assert(variableInfo != null, "variableInfo != null"); ReturnType = variableInfo.VariableType; for (int i = 1; i < Children.Count; i++) { var tmp = Children[i]; if (tmp is DotNode) { var recordTypeInfo = TypeInfo.RecordFromTypeInfo(ReturnType); if (recordTypeInfo != null) { TypeInfo value; bool memberExists = recordTypeInfo.Fields.TryGetValue(((DotNode)tmp).MemberName, out value); if (memberExists) { ReturnType = value; } else { report.AddError(this, "Unknown member."); ReturnType = null; break; } } else { report.AddError(this, "Dot operator applied to an invalid type."); break; } } else if (tmp is IndexingNode) { if (ReturnType is AliasTypeInfo) { ReturnType = (ReturnType as AliasTypeInfo).TargetType; } if (ReturnType is ArrayTypeInfo) { ReturnType = ((ArrayTypeInfo)ReturnType).TargetType; } else { report.AddError(this, "Trying to index on a non-array type."); break; } } else { throw new ArgumentOutOfRangeException("Invalid child node of LValue detected."); } } } }