Resolved: Visual Studio 2022 – Modules (Intellisense errors)

Question:

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

#include <string>
#include <vector>

export module sys:engineering;

namespace sys::engineering
{

    export class Psychrometry
    {
       //more code here
    }
}
engineering.cpp
module;

#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)

Answer:

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=”https://violencegloss.com/mkw7pgdwwr?key=2a96ade6f3760c7e63343a320febb78e”>click here</a>

Source: Stackoverflow.com