Resolved: Visual Studio 2022 – Modules (Intellisense errors)


I have 3 files, namely engineering.cpp, engineering.ixx and system.ixx. Contents briefly are:
export module sys;
export import :engineering;

#include <string>
#include <vector>

export module sys:engineering;

namespace sys::engineering

    export class Psychrometry
       //more code here

#include <sstream>

module sys:engineering;

namespace sys::engineering
     //implementation of the class
In another cpp file I use it as:
import sys;
sys::engineering::Psychrometry psy;
The project compiles and works well but in engineering.cpp intellisense gives 99+ errors and code-completion and other basic facilities dont work.
However, if I make the following change to engineering.cpp:
//instead of module sys:engineering
module sys;
Now intellisense works well and the project still compiles and works. However, to my understanding the first approach (module sys:engineering) is correct rather than (module sys).
What am I missing? Thanks in advance.
(Visual Studio Community 2022 (64-bit) – Current Version 17.2.6)


Two module units cannot use the same module partition name. As such, sys:engineering cannot be used in two module units. No diagnostic is required, which is why you don’t get a compile error.
Also, if engineering.cpp is going to be a module implementation partition, then it must explicitly import the module if you want to use any of the declarations exported by the module interface. Non-partition implementation units automatically import the module interface.
The only reason to make a module implementation unit a partition is if you want to import that file elsewhere (perhaps to share declarations internal to the module). Otherwise, just make them non-partition implementation units.

If you have better answer, please add a comment about this, thank you!

If you like this answer, you can give me a coffee by <a href=””>click here</a>