id,node_id,number,title,user,state,locked,assignee,milestone,comments,created_at,updated_at,closed_at,author_association,active_lock_reason,draft,pull_request,body,reactions,performed_via_github_app,state_reason,repo,type
342426261,MDU6SXNzdWUzNDI0MjYyNjE=,2299,Confusing behaviour with MultiIndex,1882397,closed,0,6815844,,1,2018-07-18T17:41:12Z,2018-08-13T22:16:31Z,2018-08-13T22:16:31Z,NONE,,,,"`Dataset` allows assignment of new variables with dimension names that are used in a MultiIndex, even if the lengths do not match the existing coordinate.

```python
a = pd.DataFrame({'a': [1, 2], 'b': [3, 4]}).unstack('a')
a.index.names = ['dim0', 'dim1']
a.index.name = 'stacked_dim'

b = xr.Dataset(coords={'dim0': ['a', 'b'], 'dim1': [0, 1]})
b = b.stack(dim_stacked=['dim0', 'dim1'])
assert(len(b.dim0) == 4)

# This should raise an errors because the length is != 4
b['c'] = (('dim0',), [10, 11])
b
```
Instead, it reports `dim0` as a new dimension without coordinates:
```
<xarray.Dataset>
Dimensions:      (dim0: 2, dim_stacked: 4)
Coordinates:
  * dim_stacked  (dim_stacked) MultiIndex
  - dim0         (dim_stacked) object 'a' 'a' 'b' 'b'
  - dim1         (dim_stacked) int64 0 1 0 1
Dimensions without coordinates: dim0
Data variables:
    c            (dim0) int64 10 11
```

Similar cases of coordinates that aren't used do raise an error:
```python
ds = xr.Dataset()
ds.coords['a'] = [1, 2, 3]
ds = ds.sel(a=1)
ds['b'] = (('a',), [1, 2])
ds
```

#### Output of ``xr.show_versions()``

<details>

```
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Darwin
OS-release: 17.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_GB.UTF-8
LANG: None
LOCALE: en_GB.UTF-8

xarray: 0.10.7
pandas: 0.23.2
numpy: 1.14.5
scipy: 1.1.0
netCDF4: 1.4.0
h5netcdf: None
h5py: 2.8.0
Nio: None
zarr: None
bottleneck: 1.2.1
cyordereddict: None
dask: 0.18.1
distributed: 1.22.0
matplotlib: 2.2.2
cartopy: None
seaborn: 0.8.1
setuptools: 39.2.0
pip: 10.0.1
conda: 4.5.8
pytest: 3.6.2
IPython: 6.4.0
sphinx: 1.7.5
```

</details>
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/2299/reactions"", ""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue