Skip to content

Commit

Permalink
Fixed stupid issue where types would be treated as matches for the re…
Browse files Browse the repository at this point in the history
…adonly generator even if they didn't have the right attribute.
  • Loading branch information
MeltyPlayer committed Apr 26, 2024
1 parent 37b227b commit d75513f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Schema Tests/readOnly/ReadOnlyReferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,5 +343,51 @@ public interface IReadOnlyWrapper<T> {

""");
}

[Test]
public void TestIgnoresFakeMatches() {
ReadOnlyGeneratorTestUtil.AssertGenerated(
"""
using schema.readOnly;
using foo.bar.correct;
using foo.bar.wrong;

namespace foo.bar.correct {
public class Other;
}

namespace foo.bar.correct {
[GenerateReadOnly]
public partial interface IOther;
}

namespace foo.bar {
[GenerateReadOnly]
public partial interface IWrapper {
IReadOnlyOther Field { get; set; }
}
}
""",
"""
namespace foo.bar.correct {
public partial interface IOther : IReadOnlyOther;

public interface IReadOnlyOther;
}

""",
"""
namespace foo.bar {
public partial interface IWrapper : IReadOnlyWrapper {
correct.IReadOnlyOther IReadOnlyWrapper.Field => Field;
}

public interface IReadOnlyWrapper {
public correct.IReadOnlyOther Field { get; }
}
}

""");
}
}
}
1 change: 1 addition & 0 deletions Schema/src/readOnly/ReadOnlyTypeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ public static IEnumerable<INamedTypeSymbol> LookupTypesWithNameAndArity(
int arity)
=> semanticModel
.LookupNamespacesAndTypes(syntax.SpanStart, null, searchString)
.Where(symbol => symbol.HasAttribute<GenerateReadOnlyAttribute>())
.Where(symbol => symbol is INamedTypeSymbol)
.Select(symbol => symbol as INamedTypeSymbol)
.Where(symbol => symbol.Arity == arity);
Expand Down

0 comments on commit d75513f

Please sign in to comment.