Works perfectly for me. I guess it’s a block problem. Maybe your base1's block appears after the base2's one and overrides the value.
The problem would appear with this code for example:
#base2.html.twig
{% extends 'base1.html.twig' %}
{% block content %}
{% set show = 1 %}
{{ parent() }}
{{ show }}
{% endblock %}
You should try this:
#layout.html.twig
{% block content %}
{% set show = 0 %}
{{ show }}
{% endblock %}
#base1.html.twig
{% extends 'layout.html.twig' %}
{% block content %}
{{ parent() }}
{% set show = 1 %}
{{ show }}
{% endblock %}
#base2.html.twig
{% extends 'base1.html.twig' %}
{% block content %}
{{ parent() }}
{% set show = 2 %}
{{ show }}
{% endblock %}
Displaying show
variable at each step of the inheritance process, should help you to see what’s going wrong. The final response should display 0 1 2
.