Having troubles with env()

As per the docs on Conditional Stages:

stages:
  - name: deploy
    # require the branch name to be master (note for PRs this is the base branch name)
    if: branch = master

So what seems to not work is the above approach, meaning when the condition is included in the block stages to specify the ordering. If the condition is specified in the stage definition block then it works. Consider this config:

env:
  global:
  - SOMEBRANCH: "dev"

stages:
- if: branch = env(SOMEBRANCH)
  name: One
- name: Two
  if: branch = "dev"
- name: Three
  if: branch = env(SOMEBRANCH)
- name: Hope
  if: branch = env(SOMEBRANCH)
- name: Four

jobs:
  include:
  - stage: One
    name: Job 0
    install: skip
    script: echo "Stage One depends on env()"
  - stage: Two
    name: Job Zero
    install: skip
    script: echo "Stage Two does NOT depend on env()"
  - if: branch = env(SOMEBRANCH)
    name: Job One
    install: skip
    script: echo "Job One depends on env()"
  - if: branch = "dev"
    name: Job Two
    install: skip
    script: echo "Job Two does NOT depend on env()"
  - stage: Three
    name: Hope
    install: skip
    script: echo "Stage Three depends on env()"
  - if: branch = env(SOMEBRANCH)
    stage: Four
    name: Persevere
    install: skip
    script: echo "Stage Four depends on env()"

Only stages Two and Four are built.