NMFCode / NMF

This repository contains the entire code for the .NET Modeling Framework
BSD 3-Clause "New" or "Revised" License
36 stars 15 forks source link

Some names in .ecore file can cause compilation errors #65

Closed phxnsharp closed 2 years ago

phxnsharp commented 2 years ago

Some names used in a source .ecore file cause compilation errors after following the basic tutorial.

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="model" nsURI="http://ns.ansys.com/test_model" nsPrefix="model">
  <eClassifiers xsi:type="ecore:EClass" name="Element" abstract="true">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
        iD="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Tree" abstract="true" eSuperTypes="#//Element">
    <eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1"
        eType="#//Element" containment="true"/>
  </eClassifiers>
</ecore:EPackage>

Compilation errors:

1>------ Build started: Project: NMFDemo, Configuration: Debug Any CPU ------
1>C:\Users\nsharp\source\repos\NMFDemo\NMFDemo\Metamodel\ITree.cs(53,41,53,49): warning CS0108: 'ITree.Children' hides inherited member 'IModelElement.Children'. Use the new keyword if hiding was intended.
1>C:\Users\nsharp\source\repos\NMFDemo\NMFDemo\Metamodel\Element.cs(226,51,226,56): error CS0118: 'Model' is a namespace but is used like a type
1>C:\Users\nsharp\source\repos\NMFDemo\NMFDemo\Metamodel\Element.cs(226,67,226,72): error CS0118: 'Model' is a namespace but is used like a type
1>C:\Users\nsharp\source\repos\NMFDemo\NMFDemo\Metamodel\Tree.cs(71,48,71,56): warning CS0114: 'Tree.Children' hides inherited member 'ModelElement.Children'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
1>C:\Users\nsharp\source\repos\NMFDemo\NMFDemo\Metamodel\Tree.cs(82,62,82,70): error CS0102: The type 'Tree' already contains a definition for 'Children'
1>Done building project "NMFDemo.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I am using VS 2019 with NMF-Basic 2.0.176.

Renaming 'model' to 'model2' and 'children' to 'children2' resolves the issue, but changes the DSL.

georghinkel commented 2 years ago

Hi,

first, sorry for the late reply, I was on holidays and did not read any emails.

Yes, these compilation issues happen on name clashes. Theoretically, this should not be too hard to achieve since already now many places in the code generator really trace the created code element (e.g. property) and take the name from there instead of creating a fresh one. However, I don't have time for it until Thursday.

Best,

Georg

georghinkel commented 2 years ago

Conceptwise, I experienced that resolving these name clashes with an appended _ does least harm to the readability, so I guess I will try whether that works and only resort to numbers otherwise.