summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-check-decl.cpp47
-rw-r--r--source/slang/slang-diagnostic-defs.h6
2 files changed, 45 insertions, 8 deletions
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index 21a16cae5..da2300d8a 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -10589,6 +10589,7 @@ void SemanticsDeclHeaderVisitor::visitIncludeDecl(IncludeDecl* decl)
if (fileDecl->members.getCount() == 0)
return;
+
auto firstMember = fileDecl->members[0];
if (auto moduleDeclaration = as<ModuleDeclarationDecl>(firstMember))
{
@@ -10610,6 +10611,7 @@ void SemanticsDeclHeaderVisitor::visitIncludeDecl(IncludeDecl* decl)
auto moduleName = getSimpleModuleName(implementing->moduleNameAndLoc.name);
auto expectedModuleName = moduleDecl->getName();
bool shouldSkipDiagnostic = false;
+
if (moduleDecl->members.getCount())
{
if (auto moduleDeclarationDecl = as<ModuleDeclarationDecl>(moduleDecl->members[0]))
@@ -10629,16 +10631,44 @@ void SemanticsDeclHeaderVisitor::visitIncludeDecl(IncludeDecl* decl)
}
}
}
- if (!shouldSkipDiagnostic && !moduleName.getUnownedSlice().caseInsensitiveEquals(
- getText(expectedModuleName).getUnownedSlice()))
+
+ if (!shouldSkipDiagnostic)
{
- getSink()->diagnose(
- decl->moduleNameAndLoc.loc,
- Diagnostics::includedFileDoesNotImplementCurrentModule,
- expectedModuleName,
- moduleName);
- return;
+ // First check for the case when the user has put a file extension
+ // in the include path
+ String moduleNameStr = moduleName.getUnownedSlice();
+ String expectedModuleNameStr = getText(expectedModuleName).getUnownedSlice();
+
+ // Check if module name has a source file extension
+ if (moduleNameStr.endsWith(".slang"))
+ {
+ String normalizedName = moduleNameStr.subString(0, moduleNameStr.getLength() - 6);
+
+ // If the normalized name would match, emit warning but continue
+ if (normalizedName.getUnownedSlice().caseInsensitiveEquals(
+ expectedModuleNameStr.getUnownedSlice()))
+ {
+ getSink()->diagnose(
+ implementing->moduleNameAndLoc.loc,
+ Diagnostics::moduleImplementationHasFileExtension,
+ moduleNameStr,
+ normalizedName);
+ return;
+ }
+ }
+
+ if (!moduleNameStr.getUnownedSlice().caseInsensitiveEquals(
+ expectedModuleNameStr.getUnownedSlice()))
+ {
+ getSink()->diagnose(
+ decl->moduleNameAndLoc.loc,
+ Diagnostics::includedFileDoesNotImplementCurrentModule,
+ expectedModuleName,
+ moduleName);
+ return;
+ }
}
+
return;
}
@@ -10648,6 +10678,7 @@ void SemanticsDeclHeaderVisitor::visitIncludeDecl(IncludeDecl* decl)
name);
}
+
void SemanticsDeclScopeWiringVisitor::visitImplementingDecl(ImplementingDecl* decl)
{
// Don't need to do anything unless we are in a language server context.
diff --git a/source/slang/slang-diagnostic-defs.h b/source/slang/slang-diagnostic-defs.h
index 21bf73d6e..089b57c38 100644
--- a/source/slang/slang-diagnostic-defs.h
+++ b/source/slang/slang-diagnostic-defs.h
@@ -933,6 +933,12 @@ DIAGNOSTIC(
implementingMustReferencePrimaryModuleFile,
"the source file referenced by 'implementing' must be a primary module file starting with a "
"'module' declaration.")
+DIAGNOSTIC(
+ 30506,
+ Warning,
+ moduleImplementationHasFileExtension,
+ "implementing directive contains file extension in module name '$0'. Module names should not "
+ "include extensions. The compiler will use '$1' as the module name.")
// Visibilty
DIAGNOSTIC(30600, Error, declIsNotVisible, "'$0' is not accessible from the current context.")