11package tools.samt.semantic
22
33import tools.samt.common.DiagnosticController
4+ import tools.samt.common.Location
45
56internal class SemanticModelPostProcessor (private val controller : DiagnosticController ) {
67 /* *
@@ -139,8 +140,18 @@ internal class SemanticModelPostProcessor(private val controller: DiagnosticCont
139140 }
140141
141142 private fun checkProvider (provider : ProviderType ) {
143+ val implementsTypes = mutableMapOf<ServiceType , Location >()
142144 provider.implements.forEach { implements ->
143145 checkServiceType(implements.service) { type ->
146+ implementsTypes.putIfAbsent(type, implements.definition.location)?.let { existingLocation ->
147+ controller.createContext(implements.definition.location.source).error {
148+ message(" Service '${type.name} ' already implemented" )
149+ highlight(" duplicate implements" , implements.definition.location)
150+ highlight(" previous implements" , existingLocation)
151+ }
152+ return @forEach
153+ }
154+
144155 implements.operations = if (implements.definition.serviceOperationNames.isEmpty()) {
145156 type.operations
146157 } else {
@@ -162,9 +173,19 @@ internal class SemanticModelPostProcessor(private val controller: DiagnosticCont
162173 }
163174
164175 private fun checkConsumer (consumer : ConsumerType ) {
176+ val usesTypes = mutableMapOf<ServiceType , Location >()
165177 checkProviderType(consumer.provider) { providerType ->
166178 consumer.uses.forEach { uses ->
167179 checkServiceType(uses.service) { type ->
180+ usesTypes.putIfAbsent(type, uses.definition.location)?.let { existingLocation ->
181+ controller.createContext(uses.definition.location.source).error {
182+ message(" Service '${type.name} ' already used" )
183+ highlight(" duplicate uses" , uses.definition.location)
184+ highlight(" previous uses" , existingLocation)
185+ }
186+ return @forEach
187+ }
188+
168189 val matchingImplements =
169190 providerType.implements.find { (it.service as ResolvedTypeReference ).type == type }
170191 if (matchingImplements == null ) {
0 commit comments