Using multiple `extends` can lead to unexpected results

While trying to use extends, I found several problems that I reproduced in this test project: https://gitlab.com/rymai/extends-issue/blob/master/.gitlab-ci.yml / https://gitlab.com/rymai/extends-issue/pipelines/36758225):

Implicit stage

  1. Extending from a first job with an explicit stage, then from a second job without an explicit stage results in the implicit test stage from the second job being used, e.g. https://gitlab.com/rymai/extends-issue/-/jobs/121132154.

  2. Inverting the extends solves the problem so that the explicit stage from the last job extended is used

Implicit before_script

  1. Extending from a first job with an explicit before_script, then from a second job without an explicit before_script results in a global before_script being used, e.g. https://gitlab.com/rymai/extends-issue/-/jobs/121132154

Implicit script

  1. Extending from a first job with an explicit script, then from a second job without an explicit script results in the implicit nil script from the second job being used, leading to a CI lint error jobs:extends_from_second script can't be blank, e.g. https://gitlab.com/rymai/extends-issue/pipelines/36755431