Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Incorrect "Type mismatch" error due to duplicate type hierarchy in editor
Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780100] Wed, 17 January 2018 11:56 Go to next message
Balz Guenat is currently offline Balz GuenatFriend
Messages: 17
Registered: January 2018
Junior Member
Incorrect "type mismatch" error due to duplicate type hierarchy in editor

Hi there,

We are using a DSL based on xbase and the associated features to use it in Eclipse.
Our issue is that we get incorrect "type mismatch" errors in the editor.
We do not get these errors in the Package Explorer.
These incorrect errors only appear after the opened file has been saved at least once.
After saving, any change, even just inserting (valid) whitespace, will trigger the errors.
Saving again will not remove the errors and the package explorer (correctly) continues to show no errors.
The only way we found to get rid of the errors (or annotations thereof) is to close the file and reopen it (saving and editing will again cause the errors).

This is consistently reproducible using the following steps:
1. Open the (valid) file.
2. Make any change to it, like inserting and removing again a newline at the end.
3. Save the file.
4. Make any change.

I have yet to produce a minimal example that exhibits this behavior but here is the current context:

package com.siemens.mo.idp.idc.example
// this is a regular Java class
import com.siemens.mo.idp.base.model.TableDomNodeList
// this is a namespace containing simple_table
import com.siemens.mo.idp.idc.example.def.simple_module.*

checker SimpleChecker {
   release *
   category ExampleCategory
   use table simple_table
   check checkAfTaskVerzeichnis {
	  // signature of the following constructor is public TableDomNodeList(final TableDocument)
      for (haupt : new TableDomNodeList(simple_table)) { // here simple_table throws the type mismatch error
         protocol haupt.toString
      }
   }
}


simple_table has type simple_module_simple_table which directly extends TableDocument.
Therefore it should be usable as an argument for the TableDomNodeList constructor.

Debugging reveals that the reason these types are deemed incompatible is that at the time of the check, there seem to exist two duplicate (or at least similar) type hierarchies.
The expected type, coming from the declaration of the constructor, lies in one type hierarchy whereas the actual type, coming from the declaration of simple_table, lies in the other type hierarchy.
When the type checker walks up the hierarchy starting from the actual type simple_module_simple_table, it will indeed find a type called TableDocument, but that type (or rather the object it is represented by) is not the same TableDocument that is required by the constructor.
That is, we have two identical objects representing the TableDocument type. Since these objects are compared using a normal "==" in ParameterizedTypeReference::getSuperType(...), they are not deemed equal.
The type checker continues its walk up the hierarchy until the end and deems the types incompatible, causing the type mismatch error.

This raises the following, possibly related questions:
Why are there two type hierarchies?
Why are the errors only present in the editor version of the file but not the disk files?
Why do the errors only appear after the file has been saved?
And finally and most importantly, how can we get rid of the incorrect errors?
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780124 is a reply to message #1780100] Wed, 17 January 2018 16:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12189
Registered: July 2009
Senior Member
could you share a domain model like reproducing example? what does the inferrer do?

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780150 is a reply to message #1780124] Thu, 18 January 2018 08:17 Go to previous messageGo to next message
Balz Guenat is currently offline Balz GuenatFriend
Messages: 17
Registered: January 2018
Junior Member
Thanks for the reply. I'm still working on making that minimal example so I can post it. The short of it is that the code inside the check block is put inside a method to be run. The use table statement instantiates an object of the class generated in simple_module. Details will follow shortly.
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780198 is a reply to message #1780150] Thu, 18 January 2018 14:43 Go to previous messageGo to next message
Balz Guenat is currently offline Balz GuenatFriend
Messages: 17
Registered: January 2018
Junior Member
Alright, so here is a pretty compact environment where I could replicate the error.

Grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

DomainModel:
   packageDeclaration=PackageDeclaration;
    
Module:
   'module' name=ValidID '{'
   tables+=Table+
   '}';
   
Table:
   'table' name=ValidID;

UseTable:
   'use' 'table' table=[Table];

PackageDeclaration:
   'package' name=QualifiedName
   importSection=XImportSection?
   (module=Module |
   checker=Checker);
    
Checker:
   'checker' name=ValidID '{'
   useTables+=UseTable+
   checks+=Check+
   '}';

Check:
   'check' name=ValidID
   body=XBlockExpression;

Inferrer:
/*
 * generated by Xtext 2.13.0
 */
package org.xtext.example.mydsl.jvmmodel

import com.google.inject.Inject
import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer
import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor
import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder
import org.xtext.example.mydsl.myDsl.DomainModel
import org.eclipse.xtext.naming.IQualifiedNameProvider
import org.eclipse.xtext.naming.QualifiedName
import org.eclipse.xtext.common.types.JvmGenericType
import java.util.Map
import org.xtext.example.mydsl.myDsl.*
import org.eclipse.xtext.common.types.JvmField
import sharedclasses.BaseTable
import org.eclipse.xtext.common.types.JvmConstructor

/**
 * <p>Infers a JVM model from the source model.</p> 
 *
 * <p>The JVM model should contain all elements that would appear in the Java code 
 * which is generated from the source model. Other models link against the JVM model rather than the source model.</p>     
 */
class MyDslJvmModelInferrer extends AbstractModelInferrer {

	/**
	 * convenience API to build and initialize JVM types and their members.
	 */
	@Inject extension JvmTypesBuilder
	@Inject extension IQualifiedNameProvider

	/** Global repository for Table classes. */
	static Map<QualifiedName, JvmGenericType> tableClasses = <QualifiedName, JvmGenericType>newLinkedHashMap()
	
	def dispatch void infer(Module module, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
		
		System.out.println(String.format("Inferring Module (%d)", 0));

		// infer Table classes
		for (table : module.tables) {
			infer(table, acceptor, isPreIndexingPhase)
		}

		acceptor.accept(module.toClass(module.fullyQualifiedName)) [
			for (table : module.tables) {
				members += inferTableField(table)
			}
		]
	}

	/**
	 * Calculates the fully qualified name of the Table's class.<br>
	 * If the Table is contained (ie. by a IDC Checker or Module),
	 * then the class's simple name is constructed by the container's name and the Table's name. 
	 */
	def QualifiedName getTableClassQN(Table table) {
		var QualifiedName tableQN
		if (table.eContainer !== null) {
			tableQN = table.eContainer.fullyQualifiedName
		}
		if (tableQN === null) {
			tableQN = table.fullyQualifiedName
		}
		return tableQN.skipLast(1).append(tableQN.lastSegment + '_' + table.name)
	}

	/**
	 * Infers the Table's class and registers the class in the global repository. 
	 */
	def dispatch void infer(Table table, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
		val tableClassQN = getTableClassQN(table)
		val JvmGenericType tableClass = table.toClass(tableClassQN) [
			superTypes += BaseTable.typeRef
			val JvmConstructor constructor = table.toConstructor[]
			constructor.body = []
			members += constructor
		]
		acceptor.accept(tableClass)
		tableClasses.put(tableClassQN, tableClass)
	}

	/**
	 * Infers a field with the type of the Table's class taken from the global repository.
	 */
	def JvmField inferTableField(Table table) {
		val tableClass = tableClasses.get(getTableClassQN(table))
		return table.toField(table.name, tableClass.typeRef) [
			initializer = [
				append('''
					new «tableClass.typeRef.qualifiedName»()
				''')
			]
		]
	}
	
	def dispatch void infer(Checker checker, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {

		acceptor.accept(checker.toClass(checker.fullyQualifiedName)) [

			// process Use Table Declarations
			for (useTable : checker.useTables) {
				members += inferTableField(useTable.table)
			}

			// process Check Declarations
			for (check : checker.checks) {
				members += check.toMethod(check.name, void.typeRef) [
					body = check.body
				]
			}
		]
	}
}

There are two files written in the DSL. First, SimpleChecker.mydsl:
package mypackage

import mypackage.simple_module.*
import mypackage2.Foo

//new ClassA("")
//"things"

checker SimpleChecker {

   use table simple_table

   check simpleCheck {
   	new Foo(simple_table)
   }
}

Second, simple_module.mydsl:
package mypackage

module simple_module {
   table simple_table
}

Foo is a very simple class:
package mypackage2;

import sharedclasses.BaseTable;

public class Foo {
	
	public Foo(BaseTable b) {}

}


The package sharedclasses, which is used by both the inferrer and the SimpleChecker has a single class BaseTable:
package sharedclasses;

public class BaseTable {

}


Please ask if anything is unclear.
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780204 is a reply to message #1780198] Thu, 18 January 2018 15:23 Go to previous messageGo to next message
Balz Guenat is currently offline Balz GuenatFriend
Messages: 17
Registered: January 2018
Junior Member
Correction to OP: Looks like there aren't actually two duplicate type hierarchies. Rather, there are two objects both representing the BaseTable (or TableDocument, in the OP example) type but both of these objects have the same "Object" supertype so they do appear to be in the same type graph, at least.
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780205 is a reply to message #1780204] Thu, 18 January 2018 15:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12189
Registered: July 2009
Senior Member
ähmm are you sure ypou dont have two basetables?
what happens if you replace

superTypes += BaseTable.typeRef

with

superTypes += "sharedclasses.BaseTable".typeRef



Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780206 is a reply to message #1780198] Thu, 18 January 2018 15:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12189
Registered: July 2009
Senior Member
ähmmm what is

org.xtext.example.mydsl.jvmmodel.MyDslJvmModelInferrer.tableClasses

for?


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780208 is a reply to message #1780206] Thu, 18 January 2018 15:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12189
Registered: July 2009
Senior Member
def JvmField inferTableField(Table table) {
return table.toField(table.name, getTableClassQN(table).toString.typeRef) [
initializer = [
append('''
new «getTableClassQN(table).toString.typeRef.qualifiedName»()
''')
]
]
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780281 is a reply to message #1780208] Fri, 19 January 2018 15:30 Go to previous messageGo to next message
Balz Guenat is currently offline Balz GuenatFriend
Messages: 17
Registered: January 2018
Junior Member
Quote:

ähmm are you sure ypou dont have two basetables?
what happens if you replace

superTypes += BaseTable.typeRef

with

superTypes += "sharedclasses.BaseTable".typeRef

No difference
Quote:

ähmmm what is

org.xtext.example.mydsl.jvmmodel.MyDslJvmModelInferrer.tableClasses

for?

It was supposed to map fully qualified names to JvmTypes. I say "was" because I have since removed it and am now using the lookup by String, like you suggested.

This solved my initial problem (and I thank you for that!) but I now have a different one. In the full DSL, a table may also be defined in a checker directly, i.e. the Checker rule looks more like this:
Checker:
   'checker' name=ValidID '{'
   (useTables+=UseTable |
   tables+= Table)+
   checks+=Check+
   '}';

Now, if a checker defines a table and references it in a check, the type lookup in inferTableField will fail in the first pass and result in a JvmUnknownTypeReference. Only on subsequent passes, the lookup succeeds and the correct type is found.
This might not matter much when working with the DSL (the error disappears after the next keypress) but it causes many of our unit tests to fail.
What can I do to make sure the type is lookup-able by string immediately?
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780285 is a reply to message #1780281] Fri, 19 January 2018 15:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12189
Registered: July 2009
Senior Member
if i fix inferTableField and dont use that strange map i can no longer reproduce

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780286 is a reply to message #1780285] Fri, 19 January 2018 15:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12189
Registered: July 2009
Senior Member
p.s. make sure you respect isPreIndexingPhase
you should lookup derived types only if its false


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780293 is a reply to message #1780286] Fri, 19 January 2018 16:24 Go to previous messageGo to next message
Balz Guenat is currently offline Balz GuenatFriend
Messages: 17
Registered: January 2018
Junior Member
Quote:
if i fix inferTableField and dont use that strange map i can no longer reproduce

Reproduce the original issue or the new one I described?
Quote:
p.s. make sure you respect isPreIndexingPhase
you should lookup derived types only if its false

The failing unit tests I mentioned are parsing/validation tests, i.e. they look like
	@Inject extension ParseHelper<IltisDataCheckerModel>
	@Inject extension ValidationTestHelper
	@Test
	def void simpleCheckerWithTable() {'''<DSL code>'''.parse.assertNoIssues}

They use the default BatchLinkableResource, which seems to only call the inferrer only once, with isPreIndexingPhase set to false. Other unit tests that call compile on the same code run two phases and succeed. Am I not supposed to call assertNoIssues after parse? Do I need to add an additional step beforehand to run a pre-indexing phase?

Thanks for your continued help!
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780296 is a reply to message #1780293] Fri, 19 January 2018 16:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12189
Registered: July 2009
Senior Member
can you please share a complete example project

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780299 is a reply to message #1780296] Fri, 19 January 2018 17:03 Go to previous messageGo to next message
Balz Guenat is currently offline Balz GuenatFriend
Messages: 17
Registered: January 2018
Junior Member
Same project setup as before.
SimpleChecker.mydsl:
package mypackage

import mypackage2.Foo

checker SimpleChecker {

   table simple_table

   check simpleCheck {
   	new Foo(simple_table)
   }
}

MyDsl.xtext:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

DomainModel:
   packageDeclaration=PackageDeclaration;
    
Module:
   'module' name=ValidID '{'
   tables+=Table+
   '}';
   
Table:
   'table' name=ValidID;

UseTable:
   'use' 'table' table=[Table];

PackageDeclaration:
   'package' name=QualifiedName
   importSection=XImportSection?
   (module=Module |
   checker=Checker);
    
Checker:
   'checker' name=ValidID '{'
   (useTables+=UseTable |
   	tables+=Table)+
   checks+=Check+
   '}';

Check:
   'check' name=ValidID
   body=XBlockExpression;

MyDslJvmModelInferrer.xtend:
/*
 * generated by Xtext 2.13.0
 */
package org.xtext.example.mydsl.jvmmodel

import com.google.inject.Inject
import org.eclipse.xtext.xbase.jvmmodel.AbstractModelInferrer
import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor
import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder
import org.xtext.example.mydsl.myDsl.DomainModel
import org.eclipse.xtext.naming.IQualifiedNameProvider
import org.eclipse.xtext.naming.QualifiedName
import org.eclipse.xtext.common.types.JvmGenericType
import java.util.Map
import org.xtext.example.mydsl.myDsl.*
import org.eclipse.xtext.common.types.JvmField
import sharedclasses.BaseTable
import org.eclipse.xtext.common.types.JvmConstructor

/**
 * <p>Infers a JVM model from the source model.</p> 
 *
 * <p>The JVM model should contain all elements that would appear in the Java code 
 * which is generated from the source model. Other models link against the JVM model rather than the source model.</p>     
 */
class MyDslJvmModelInferrer extends AbstractModelInferrer {

	/**
	 * convenience API to build and initialize JVM types and their members.
	 */
	@Inject extension JvmTypesBuilder
	@Inject extension IQualifiedNameProvider
	
	def dispatch void infer(Module module, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {

		// infer Table classes
		for (table : module.tables) {
			infer(table, acceptor, isPreIndexingPhase)
		}

		acceptor.accept(module.toClass(module.fullyQualifiedName)) [
			for (table : module.tables) {
				members += inferTableField(table)
			}
		]
	}

	/**
	 * Calculates the fully qualified name of the Table's class.<br>
	 * If the Table is contained (ie. by a IDC Checker or Module),
	 * then the class's simple name is constructed by the container's name and the Table's name. 
	 */
	def QualifiedName getTableClassQN(Table table) {
		var QualifiedName tableQN
		if (table.eContainer !== null) {
			tableQN = table.eContainer.fullyQualifiedName
		}
		if (tableQN === null) {
			tableQN = table.fullyQualifiedName
		}
		return tableQN.skipLast(1).append(tableQN.lastSegment + '_' + table.name)
	}

	/**
	 * Infers the Table's class and registers the class in the global repository. 
	 */
	def dispatch void infer(Table table, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {
		val tableClassQN = getTableClassQN(table)
		val JvmGenericType tableClass = table.toClass(tableClassQN) [
			superTypes += BaseTable.typeRef
			val JvmConstructor constructor = table.toConstructor[]
			constructor.body = []
			members += constructor
		]
		acceptor.accept(tableClass)
	}

	/**
	 * Infers a field with the type of the Table's class taken from the global repository.
	 */
	def JvmField inferTableField(Table table) {
		val tableClassQN = getTableClassQN(table)
		return table.toField(table.name, tableClassQN.toString.typeRef) [
			initializer = [
				append('''
					new «tableClassQN.toString.typeRef.qualifiedName»()
				''')
			]
		]
	}
	
	def dispatch void infer(Checker checker, IJvmDeclaredTypeAcceptor acceptor, boolean isPreIndexingPhase) {

		// infer Table classes
		for (table : checker.tables) {
			infer(table, acceptor, isPreIndexingPhase)
		}

		acceptor.accept(checker.toClass(checker.fullyQualifiedName)) [

			// process Use Table Declarations
			for (useTable : checker.useTables) {
				members += inferTableField(useTable.table)
			}

			// process Table Declarations
			for (table : checker.tables) {
				members += inferTableField(table)
			}

			// process Check Declarations
			for (check : checker.checks) {
				members += check.toMethod(check.name, void.typeRef) [
					body = check.body
				]
			}
		]
	}
}


To reproduce the issue without unit tests, in SimpleChecker.mydsl, on the line "table simple_table", delete the last character (i.e. the 'e' from simple_table). The usage in the constructor should be marked, as expected. Now add back the 'e'. The usage becomes marked with a different (incorrect) error "...refers to missing type". After another input, like adding a space, the error vanishes (as it should have before).
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780300 is a reply to message #1780299] Fri, 19 January 2018 17:09 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12189
Registered: July 2009
Senior Member
but where is the test?

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780303 is a reply to message #1780300] Fri, 19 January 2018 17:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12189
Registered: July 2009
Senior Member
this is why i ask for a reproducible project ....

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780403 is a reply to message #1780303] Mon, 22 January 2018 08:38 Go to previous messageGo to next message
Balz Guenat is currently offline Balz GuenatFriend
Messages: 17
Registered: January 2018
Junior Member
I didn't have a test ready in the example. That's why I described how to reproduce the issue in the eclipse App. Anyway, now I have a test, here you go:
/*
 * generated by Xtext 2.10.0
 */
package org.xtext.example.mydsl.tests

import com.google.inject.Inject
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
import org.eclipse.xtext.testing.validation.ValidationTestHelper
import org.junit.Test
import org.junit.runner.RunWith
import org.xtext.example.mydsl.myDsl.DomainModel
import org.xtext.example.mydsl.tests.MyDslInjectorProvider
import sharedclasses.BaseTable

@RunWith(XtextRunner)
@InjectWith(MyDslInjectorProvider)
class CheckerWithTable {

	@Inject extension ParseHelper<DomainModel>
	@Inject extension ValidationTestHelper
	
	def void foo(BaseTable table) {
		System.out.println(table.class.toString)
	}

	@Test
	def void checkerWithTable() {
		'''
			package mypackage
			
			checker SimpleCheckerWithCatalog {
			   
			   table simple_table
			   
			   check SimplePointCheck {
			   	foo(simple_table)
			   }
			}
		'''.parse.assertNoIssues
	}
}
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780406 is a reply to message #1780403] Mon, 22 January 2018 08:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12189
Registered: July 2009
Senior Member
please share a complete sample project via github / gitlab and others

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780410 is a reply to message #1780406] Mon, 22 January 2018 09:23 Go to previous messageGo to next message
Balz Guenat is currently offline Balz GuenatFriend
Messages: 17
Registered: January 2018
Junior Member
Here: https://github.com/BalzGuenat/DSL-error
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780412 is a reply to message #1780410] Mon, 22 January 2018 09:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12189
Registered: July 2009
Senior Member
looks like parseHelper is not ment to work with xbase
you may try somehting like

class CheckerWithTable {

	@Inject extension ParseHelper<DomainModel>
	@Inject extension ValidationTestHelper
	@Inject CompilationTestHelper compilationTestHelper
	
	def void foo(BaseTable table) {
		System.out.println(table.class.toString)
	}

	@Test
	def void checkerWithTable() {
		compilationTestHelper.compile('''
			package mypackage
			
			checker SimpleCheckerWithCatalog {
			   
			   table simple_table
			   
			   check SimplePointCheck {
			   	foo(simple_table)
			   }
			}
		''') [result|
			Assert.assertEquals('''
		MULTIPLE FILES WERE GENERATED
		
		File 1 : /myProject/./src-gen/mypackage/SimpleCheckerWithCatalog.java
		
		package mypackage;
		
		import mypackage.SimpleCheckerWithCatalog_simple_table;
		
		@SuppressWarnings("all")
		public class SimpleCheckerWithCatalog {
		  private SimpleCheckerWithCatalog_simple_table simple_table = new mypackage.SimpleCheckerWithCatalog_simple_table()
		    ;
		  
		  public void SimplePointCheck() {
		    /* name is null */;
		  }
		}
		
		File 2 : /myProject/./src-gen/mypackage/SimpleCheckerWithCatalog_simple_table.java
		
		package mypackage;
		
		import sharedclasses.BaseTable;
		
		@SuppressWarnings("all")
		public class SimpleCheckerWithCatalog_simple_table extends BaseTable {
		  public SimpleCheckerWithCatalog_simple_table() {
		    
		  }
		}
		
		'''.toString(), result.getSingleGeneratedCode());
			val errors = result.errorsAndWarnings
			Assert.assertEquals(errors.join(","),errors,newArrayList)
		]
		
		
	
	}
}


(i dont understand your inferror logic to write a correct test)


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Incorrect "Type mismatch" error due to duplicate type hierarchy in editor [message #1780432 is a reply to message #1780412] Mon, 22 January 2018 11:28 Go to previous message
Balz Guenat is currently offline Balz GuenatFriend
Messages: 17
Registered: January 2018
Junior Member
Thanks for the suggestion but we already have compilation tests.

To solve both the jUnit and IDE issues, I have now added a map to the inferrer that maps fully qualified class names to JvmDeclaredTypes. This map is populated whenever the inferrer creates one of these problematic classes. Later, when a lookup by string of one of these types fails, I consult the map as a fallback.

This seems to work for the tests as well as the IDE.

Thanks again for the help!
Previous Topic:[Solved] Referencing to two separate types
Next Topic:TemplateProposal leads to endless loop
Goto Forum:
  


Current Time: Tue Aug 21 22:07:03 GMT 2018

Powered by FUDForum. Page generated in 0.03412 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top