@@ -102,11 +102,27 @@ private static void GenerateForProperty(
102102 Debugger . Launch ( ) ;
103103#endif
104104
105+ // Validate library name is provided
106+ if ( pAttr . ConstructorArguments . Length == 0 )
107+ {
108+ spc . ReportDiagnostic ( Diagnostic . Create (
109+ Diagnostics . MissingLibraryName ,
110+ prop . Locations [ 0 ] ) ) ;
111+ return ;
112+ }
113+ var libraryName = pAttr . ConstructorArguments [ 0 ] . Value as string ;
114+ if ( string . IsNullOrEmpty ( libraryName ) )
115+ {
116+ spc . ReportDiagnostic ( Diagnostic . Create (
117+ Diagnostics . MissingLibraryName ,
118+ prop . Locations [ 0 ] ) ) ;
119+ return ;
120+ }
121+
105122 // Attribute data
106123 NativeImportAttribute nativeImportAttr ;
107124 {
108125 var temp = new NativeImportAttribute ( string . Empty ) ; // Temporary instance to get the default values
109- var libraryName = ( string ? ) pAttr . ConstructorArguments [ 0 ] . Value ?? "__Internal" ; // TODO/FIXME: Report a diagnostic
110126 var enforceBlittable = ( bool ) ( pAttr . NamedArguments
111127 . FirstOrDefault ( static kv => kv . Key == nameof ( NativeImportAttribute . EnforceBlittable ) )
112128 . Value . Value ?? temp . EnforceBlittable ) ;
@@ -131,7 +147,7 @@ private static void GenerateForProperty(
131147 var symbolSuffix = ( pAttr . NamedArguments
132148 . FirstOrDefault ( static kv => kv . Key == nameof ( NativeImportAttribute . SymbolSuffix ) )
133149 . Value . Value ?? temp . SymbolSuffix ) as string ;
134- nativeImportAttr = new NativeImportAttribute ( libraryName )
150+ nativeImportAttr = new NativeImportAttribute ( libraryName ! )
135151 {
136152 EnforceBlittable = enforceBlittable ,
137153 ExplicitOnly = explicitOnly ,
@@ -254,6 +270,14 @@ private static void GenerateForProperty(
254270 // Generate a file per container type
255271 spc . AddSource ( $ "{ containingType . Name } .{ prop . Name } -{ Guid . NewGuid ( ) : N} .g.cs", source ) ; // Append Guid to avoid collisions, just in case
256272 }
273+ else
274+ {
275+ // Report warning for empty interfaces
276+ spc . ReportDiagnostic ( Diagnostic . Create (
277+ Diagnostics . EmptyInterface ,
278+ prop . Locations [ 0 ] ,
279+ iface . Name ) ) ;
280+ }
257281 }
258282
259283 private static string ResolveMethodEntryPoint ( string ? entryPoint , string methodName , string ? symbolPrefix , string ? symbolSuffix )
0 commit comments