| Severity | Error |
| Reported by | Metalama.Framework |
| Message | The local variables <VariableNames> cannot be declared in the same declaration because some of them are compile-time and others are run-time. Split the declaration into two declarations: one for the compile-time variables and one for the run-time variables. |
Cause
In a template, every local variable is either compile-time or run-time. Metalama infers the scope of each variable from its initializer: a variable initialized with a compile-time value, for instance with meta.CompileTime( 0 ) or meta.Target.Parameters.Count, is a compile-time variable. A variable initialized with a run-time value, or without an initializer, is a run-time variable.
C# lets you declare several variables of the same type in a single declaration, separated by commas. Metalama reports LAMA0105 when such a declaration, in a template, contains both compile-time and run-time variables. The template compiler handles a declaration as a whole: it either evaluates it at compile time or copies it to the generated code, so it can't split it for you. In the message, <VariableNames> is the list of the names of all variables of the declaration.
This diagnostic isn't reported when the type of the declaration is a compile-time-only type, such as IMethod, because all variables of the declaration are then compile-time variables.
In the current version of Metalama, the template compiler stops with an unexpected error right after reporting this diagnostic, so it can't be shown in an example.
Resolution
Split the declaration into two declarations, each with its own type: one that declares only the compile-time variables, and one that declares only the run-time variables. You can also declare each variable in its own statement.