Skip to content

inline_pragma_without_body

Reports an inlining pragma on a declaration that has no body to inline. Delete the pragma, or put it on the member that has the body.

Tier
advisory
Scope
Dart
Lowest preset
recommended
Fix
deletes the pragma, with its line where it stands alone on it

A pragma of dart:core that asks to inline a body, on a declaration that has none. The violation is on the annotation.

  • The pragmas are vm:prefer-inline, dart2js:prefer-inline, dart2js:tryInline and wasm:prefer-inline.
  • The declarations are an abstract method, getter or setter, and a class, mixin, enum, extension, extension type or typedef.

It does not report:

  • an external member, whose body is written elsewhere;
  • a field or a variable;
  • any other pragma;
  • a class of your own named pragma.

The fix is not offered where a comment stands before the pragma.

A compiler inlines the body of the function a call reaches. An abstract member has none, and an override does not take the pragma over, so the pragma asks for nothing.

Violating
abstract class Shape {
@pragma('vm:prefer-inline')
double area();
}
Corrected
abstract class Shape {
double area();
}

Set under the assay: key of the project’s root analysis_options.yaml.

Rule parameter Default Effect
enabled true false switches the rule off for the whole project.
exclude [] Path globs where the rule is silent.

Write why on the line directly above the suppression:

// Why it stays as written here.
// ignore: inline_pragma_without_body

// ignore_for_file: assay/inline_pragma_without_body silences it in a whole file, and // ignore: assay/inline_pragma_without_body with the prefix works too. See Suppressions.