Pārlūkot izejas kodu

Merge pull request #362 from Yakindu/issue_361

resolves #361
Thomas Kutz 9 gadi atpakaļ
vecāks
revīzija
03eeca0d2c

+ 4 - 3
plugins/org.yakindu.base.expressions/src/org/yakindu/base/expressions/inferrer/ExpressionsTypeInferrer.java

@@ -184,8 +184,10 @@ public class ExpressionsTypeInferrer extends AbstractTypeSystemInferrer implemen
 		return type;
 	}
 
-	// TODO: How to handle TypeAlias, like in C as weak types or like Lint
-	// strong types?
+	/**
+	 * The type of a type alias is its (recursively inferred) base type, i.e.
+	 * type aliases are assignable if their inferred base types are assignable.
+	 */
 	public Object infer(TypeAlias typeAlias) {
 		return inferTypeDispatch(typeAlias.getType());
 	}
@@ -260,7 +262,6 @@ public class ExpressionsTypeInferrer extends AbstractTypeSystemInferrer implemen
 		Type type = inferTypeDispatch(p.getType());
 		assertNotType(type, VARIABLE_VOID_TYPE, getType(VOID));
 		return inferTypeDispatch(type);
-
 	}
 
 	public Object infer(Operation e) {

+ 4 - 11
plugins/org.yakindu.base.types/src-gen/org/yakindu/base/types/impl/TypeAliasImpl.java

@@ -393,20 +393,13 @@ public class TypeAliasImpl extends EObjectImpl implements TypeAlias {
 	}
 
 	/**
-	 * <!-- begin-user-doc --> <!-- end-user-doc -->
-	 * @generated
+	 * <!-- begin-user-doc -->
+	 * <!-- end-user-doc -->
+	 * @generated NOT
 	 */
 	@Override
 	public String toString() {
-		if (eIsProxy()) return super.toString();
-
-		StringBuffer result = new StringBuffer(super.toString());
-		result.append(" (name: ");
-		result.append(name);
-		result.append(", abstract: ");
-		result.append(abstract_);
-		result.append(')');
-		return result.toString();
+		return name;
 	}
 
 } // TypeAliasImpl

+ 5 - 0
plugins/org.yakindu.base.types/src/org/yakindu/base/types/inferrer/AbstractTypeSystemInferrer.java

@@ -17,6 +17,7 @@ import java.util.Collections;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.xtext.util.PolymorphicDispatcher;
 import org.yakindu.base.types.Type;
+import org.yakindu.base.types.TypeAlias;
 import org.yakindu.base.types.typesystem.ITypeSystem;
 import org.yakindu.base.types.validation.IValidationIssueAcceptor;
 import org.yakindu.base.types.validation.IValidationIssueAcceptor.ListBasedValidationIssueAcceptor;
@@ -86,6 +87,10 @@ public abstract class AbstractTypeSystemInferrer implements ITypeSystemInferrer
 	private void initTypeCache(final EObject context) {
 		typeCache = CacheBuilder.newBuilder().maximumSize(100).build(new CacheLoader<EObject, Type>() {
 			public Type load(EObject key) {
+				if (key instanceof TypeAlias) {
+					// for type aliases we want to infer their base types
+					return (Type) (EObject) dispatcher.invoke(key);
+				}
 				if (key instanceof Type) {
 					Collection<Type> types = registry.getTypes(context);
 					for (Type type : types) {