protected override void VisitIdentifierSyntax(IdentifierSyntax pNode) { _locals.SetValue(pNode.Value, new LocalReference(pNode.Span, pNode.Value, true)); var currentStruct = Struct; var currentType = CurrentType; if (currentType != null) { var definition = currentType.GetField(pNode.Value); //Only the defining struct can access hidden fields if (definition.Visibility == FieldVisibility.Hidden && currentStruct != currentType) { //Check if the struct is a trait that implements the current type //This will allow implementing traits to access the struct's private fields if (currentStruct == null || !currentStruct.IsTrait || !currentType.IsAssignableFrom(currentStruct)) { CompilerErrors.AccessPrivateMember(pNode, pNode.Span); } } } if (currentStruct != null && Store.GetValueOrDefault <bool>("InConstructor") && Store.GetValueOrDefault <bool>("InAssignment")) { _usedFields.Add(pNode.Value); } base.VisitIdentifierSyntax(pNode); }