That is because a role that is marked with is_admin (which from the UI is possible for just a single role) has all the permissions. Consider it as an extension of the user #1 concept; the difference is that there is just a user #1, but there could be many users assigned to the role marked as is_admin.
In fact, the code does the same it does for the user #1: It explicitly checks for the role being is_admin. So, returning an array of permissions that will never be used doesn't make sense. See Role::hasPermission()
.
if ($this->isAdmin()) {
return TRUE;
}
return in_array($permission, $this->permissions);
Similar code is present in other functions/methods, for example Role::revokePermission().
if ($this->isAdmin()) {
return $this;
}
$this->permissions = array_diff($this->permissions, array($permission));
return $this;
As for why Drupal uses that code, it is because from the UI it is possible to change which role is marked as is_admin, including one for which permissions were already set. Once it is marked is_admin, the permissions explicitly set can be ignored, but they are kept, just in case you change from the UI the role marked as is_admin. In such case, you would not want to set again the permissions you set for the old is_admin role.
public function isAdmin() { return (bool) $this->is_admin; }