| Severity | Warning |
| Reported by | Metalama.Extensions.Architecture |
| Message | The '<ReferencedDeclaration>' <ReferencedDeclarationKind> is experimental.<OptionalSpace><Description> |
Cause
The ExperimentalAttribute aspect marks a declaration, typically a type or a member, as experimental. Metalama then validates every reference to this declaration and to its members, and reports LAMA0900 for each reference from code that isn't experimental.
A reference is allowed, and doesn't produce the warning, in the following situations:
- The referencing code is contained in the experimental declaration itself.
- The referencing declaration, or one of its containing declarations, is also marked with [Experimental].
In the message, <ReferencedDeclaration> is the experimental declaration and <ReferencedDeclarationKind> its kind, for instance type or method. If you pass a description to the [Experimental] attribute, the message ends with this description.
In the following example, the PdfExporter class is experimental, and the ReportService.Save method, which isn't experimental, calls it.
1using Metalama.Extensions.Architecture.Aspects;
2
3namespace Doc.LAMA0900.Error;
4
5[Experimental]
6public static class PdfExporter
7{
8 public static void Export( string path ) { }
9}
10
11public class ReportService
12{
13 public void Save()
14 {
15 // Warning: PdfExporter is experimental, but Save is not.
Warning LAMA0900: The 'PdfExporter' type is experimental.
16 PdfExporter.Export( "report.pdf" );
17 }
18}
19
Resolution
Depending on your intent, do one of the following:
- Mark the referencing declaration, or its containing type, with [Experimental] as well, so that the experimental status propagates to the code that depends on the API. The following example does this. Note that
[Experimental]can only be applied to declarations that arepublicorprotected. - Stop using the experimental API until it's stable.
- If you own the API and it's now stable, remove the
[Experimental]attribute.
1using Metalama.Extensions.Architecture.Aspects;
2
3namespace Doc.LAMA0900.Fixed;
4
5[Experimental]
6public static class PdfExporter
7{
8 public static void Export( string path ) { }
9}
10
11public class ReportService
12{
13 // Fixed: the method that uses the experimental API is marked as experimental too.
14 [Experimental]
15 public void Save()
16 {
17 PdfExporter.Export( "report.pdf" );
18 }
19}
20