Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes to source generator #3466

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Made WebSocket error logging more verbose when using `AppConfiguration.UseManagedWebSockets = true`. [#3459](https://github.com/realm/realm-dotnet/pull/3459)

### Fixed
* None
* Added an error that is raised when interface based Realm classes are used with a language version lower than 8.0. At the same time, removed the use of `not` in the generated code, so that it's compatible with a minumum C# version of 8.0. (Issue [#3265](https://github.com/realm/realm-dotnet/issues/3265))

### Compatibility
* Realm Studio: 13.0.0 or later.
Expand Down
2 changes: 1 addition & 1 deletion Realm/Realm.SourceGenerator/ClassCodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public override bool Equals(object? obj)
return !IsValid;
}

if (obj is not Realms.IRealmObjectBase iro)
if (!(obj is Realms.IRealmObjectBase iro))
{
return false;
}
Expand Down
12 changes: 11 additions & 1 deletion Realm/Realm.SourceGenerator/Diagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private enum Id
IndexedPrimaryKey = 28,
InvalidCollectionInitializer = 29,
InvalidCollectionInitializerInCtor = 30,
OldCSharpVersion = 100,
InvalidGeneratorConfiguration = 1000,
}

Expand All @@ -67,6 +68,15 @@ public static Diagnostic InvalidConfiguration(string field, string description)
Location.None);
}

public static Diagnostic OldCSharpVersion()
{
return CreateDiagnosticError(
Id.OldCSharpVersion,
"Unsupported version of C#",
$"It is not possible to use the Realm source generator with C# versions older than 8.0.",
Location.None);
}

public static Diagnostic UnexpectedError(string className, string message, string stackTrace)
{
return CreateDiagnosticError(
Expand All @@ -82,7 +92,7 @@ public static Diagnostic ClassUnclearDefinition(string className, Location locat
return CreateDiagnosticError(
Id.ClassUnclearDefinition,
"Realm classes cannot implement multiple class interfaces",
$"Class {className} is declared as implementing multiple class interfaces.A class can implement only one interface between IRealmObject, IEmbeddedObject, IAsymmetricObject.",
$"Class {className} is declared as implementing multiple class interfaces. A class can implement only one interface between IRealmObject, IEmbeddedObject, IAsymmetricObject.",
location);
}

Expand Down
2 changes: 2 additions & 0 deletions Realm/Realm.SourceGenerator/DiagnosticsEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public void Emit(ParsingResults parsingResults)
throw;
}
}

parsingResults.GeneralDiagnostics.ForEach(_context.ReportDiagnostic);
}

private static void SerializeDiagnostics(GeneratorExecutionContext context, ClassInfo classInfo)
Expand Down
10 changes: 10 additions & 0 deletions Realm/Realm.SourceGenerator/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public ParsingResults Parse(IEnumerable<RealmClassDefinition> realmClasses)
var classNames = new HashSet<string>();
var duplicateClassNames = new HashSet<string>();

if (realmClasses.Any() &&
_context.Compilation is CSharpCompilation comp &&
comp.LanguageVersion < LanguageVersion.CSharp8)
{
result.GeneralDiagnostics.Add(Diagnostics.OldCSharpVersion());
return result;
}

foreach (var rc in realmClasses)
{
var classSymbol = rc.ClassSymbol;
Expand Down Expand Up @@ -556,5 +564,7 @@ private static string RemoveUsingKeyword(UsingDirectiveSyntax syntax)
internal record ParsingResults
{
public List<ClassInfo> ClassInfo { get; } = new();

public List<Diagnostic> GeneralDiagnostics { get; } = new();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading